metamaps--metamaps/app/controllers/synapses_controller.rb

95 lines
1.8 KiB
Ruby
Raw Normal View History

2012-10-10 00:23:45 +00:00
class SynapsesController < ApplicationController
before_filter :require_user, only: [:new, :create, :edit, :update]
respond_to :html, :js, :json
# GET /synapses
def index
@user = current_user
@synapses = Synapse.all
respond_with(@synapses)
end
# Get /synapse/new
def new
2012-10-18 00:51:54 +00:00
@synapse = Synapse.new
2012-10-10 00:23:45 +00:00
@user = current_user
@allitems = Item.all
2012-10-18 00:51:54 +00:00
respond_with(@synapse, @allitems)
2012-10-10 00:23:45 +00:00
end
# GET /synapse/:id
def show
@synapse = Synapse.find(params[:id])
if @synapse
@synapsejson = @synapse.self_as_json.html_safe
2012-10-10 00:23:45 +00:00
end
respond_to do |format|
format.html
format.json { respond_with(@synapsejson) }
2012-10-10 00:23:45 +00:00
end
end
# POST /synapses
def create
@user = current_user
@synapse = Synapse.new()
@synapse.desc = params[:synapse][:desc]
@synapse.category = params[:category]
2012-10-18 00:51:54 +00:00
@synapse.item1 = Item.find(params[:node1_id])
@synapse.item2 = Item.find(params[:node2_id])
@synapse.user = @user
2012-10-10 00:23:45 +00:00
@synapse.save
respond_to do |format|
format.html { respond_with(@user, location: synapse_url(@synapse)) }
format.js { respond_with(@synapse) }
end
end
# GET /synapses/:id/edit
def edit
@synapse = Synapse.find_by_id(params[:id])
2012-10-18 00:51:54 +00:00
@items = nil
2012-10-10 00:23:45 +00:00
2012-10-18 00:51:54 +00:00
if @synapse
@items = Item.all
2012-10-10 00:23:45 +00:00
end
2012-10-18 00:51:54 +00:00
respond_with(@synapse, @items)
2012-10-10 00:23:45 +00:00
end
# PUT /synapses/:id
2012-10-10 00:23:45 +00:00
def update
@synapse = Synapse.find_by_id(params[:id])
if @synapse
@synapse.desc = params[:synapse][:desc]
2012-10-18 00:51:54 +00:00
@synapse.item1 = Item.find(params[:node1_id][:node1])
@synapse.item2 = Item.find(params[:node2_id][:node2])
2012-10-10 00:23:45 +00:00
@synapse.save
end
respond_with(@user, location: synapse_url(@synapse)) do |format|
end
end
# DELETE /synapses/:id
def destroy
@synapse = Synapse.find_by_id(params[:id])
@synapse.delete
end
end