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
|
2012-10-19 21:26:46 +00:00
|
|
|
@synapsejson = @synapse.self_as_json.html_safe
|
2012-10-10 00:23:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-10-19 21:26:46 +00:00
|
|
|
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
|
|
|
|
|
2012-10-19 21:26:46 +00:00
|
|
|
# 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
|