2012-10-10 00:23:45 +00:00
|
|
|
class SynapsesController < ApplicationController
|
2013-01-01 22:45:35 +00:00
|
|
|
include TopicsHelper
|
2012-10-10 00:23:45 +00:00
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
before_filter :require_user, only: [:create, :update, :destroy]
|
2012-10-10 00:23:45 +00:00
|
|
|
|
2014-07-29 17:34:10 +00:00
|
|
|
respond_to :json
|
2012-10-10 00:23:45 +00:00
|
|
|
|
2014-07-29 17:34:10 +00:00
|
|
|
# GET /synapses/1.json
|
|
|
|
def show
|
|
|
|
@synapse = Synapse.find(params[:id])
|
|
|
|
|
|
|
|
#.authorize_to_show(@current)
|
2013-01-18 22:08:06 +00:00
|
|
|
|
2014-07-29 17:34:10 +00:00
|
|
|
#if not @synapse
|
|
|
|
# redirect_to root_url and return
|
|
|
|
#end
|
|
|
|
|
|
|
|
render json: @synapse
|
2013-01-18 22:08:06 +00:00
|
|
|
end
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
# POST /synapses
|
|
|
|
# POST /synapses.json
|
2012-10-10 00:23:45 +00:00
|
|
|
def create
|
2015-09-19 12:05:36 +00:00
|
|
|
@synapse = Synapse.new(synapse_params)
|
2014-07-27 19:57:35 +00:00
|
|
|
|
2012-10-10 00:23:45 +00:00
|
|
|
respond_to do |format|
|
2014-07-27 19:57:35 +00:00
|
|
|
if @synapse.save
|
|
|
|
format.json { render json: @synapse, status: :created }
|
|
|
|
else
|
|
|
|
format.json { render json: @synapse.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2012-10-10 00:23:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-27 19:57:35 +00:00
|
|
|
# PUT /synapses/1
|
|
|
|
# PUT /synapses/1.json
|
2012-10-10 00:23:45 +00:00
|
|
|
def update
|
2014-07-27 19:57:35 +00:00
|
|
|
@synapse = Synapse.find(params[:id])
|
2013-01-06 04:37:24 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-09-19 12:05:36 +00:00
|
|
|
if @synapse.update_attributes(synapse_params)
|
2014-07-27 19:57:35 +00:00
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
|
|
|
format.json { render json: @synapse.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2013-01-06 04:37:24 +00:00
|
|
|
end
|
|
|
|
end
|
2012-10-10 00:23:45 +00:00
|
|
|
|
2012-12-21 23:07:13 +00:00
|
|
|
# DELETE synapses/:id
|
2012-10-10 00:23:45 +00:00
|
|
|
def destroy
|
2013-01-06 03:40:10 +00:00
|
|
|
@current = current_user
|
2015-01-29 03:35:03 +00:00
|
|
|
@synapse = Synapse.find(params[:id]).authorize_to_delete(@current)
|
2015-10-01 03:02:39 +00:00
|
|
|
@synapse.delete if @synapse
|
2014-07-27 19:57:35 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2014-08-12 22:14:04 +00:00
|
|
|
format.json { head :no_content }
|
2014-07-27 19:57:35 +00:00
|
|
|
end
|
2012-10-10 00:23:45 +00:00
|
|
|
end
|
2015-09-19 08:26:34 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def synapse_params
|
|
|
|
params.require(:synapse).permit(:id, :desc, :category, :weight, :permission, :node1_id, :node2_id, :user_id)
|
|
|
|
end
|
2012-10-10 00:23:45 +00:00
|
|
|
end
|