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

67 lines
1.5 KiB
Ruby
Raw Normal View History

2012-10-10 00:23:45 +00:00
class SynapsesController < ApplicationController
include TopicsHelper
2012-10-10 00:23:45 +00:00
2016-02-28 09:48:18 +00:00
before_action :require_user, only: [:create, :update, :destroy]
after_action :verify_authorized, except: :index
after_action :verify_policy_scoped, only: :index
2014-07-29 17:34:10 +00:00
respond_to :json
2014-07-29 17:34:10 +00:00
# GET /synapses/1.json
def show
@synapse = Synapse.find(params[:id])
2016-03-12 00:10:30 +00:00
authorize @synapse
2014-07-29 17:34:10 +00:00
render json: @synapse
end
2014-07-27 19:57:35 +00:00
# POST /synapses
# POST /synapses.json
2012-10-10 00:23:45 +00:00
def create
@synapse = Synapse.new(synapse_params)
@synapse.desc = '' if @synapse.desc.nil?
2016-03-12 00:10:30 +00:00
authorize @synapse
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])
@synapse.desc = '' if @synapse.desc.nil?
2016-03-12 00:10:30 +00:00
authorize @synapse
respond_to do |format|
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
end
end
# DELETE synapses/:id
2012-10-10 00:23:45 +00:00
def destroy
@synapse = Synapse.find(params[:id])
2016-03-12 00:10:30 +00:00
authorize @synapse
@synapse.destroy
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