2012-10-09 20:23:45 -04:00
|
|
|
class SynapsesController < ApplicationController
|
2013-01-01 17:45:35 -05:00
|
|
|
include TopicsHelper
|
2012-10-09 20:23:45 -04:00
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
before_filter :require_user, only: [:create, :update, :destroy]
|
2012-10-09 20:23:45 -04:00
|
|
|
|
2014-07-29 13:34:10 -04:00
|
|
|
respond_to :json
|
2012-10-09 20:23:45 -04:00
|
|
|
|
2014-07-29 13:34:10 -04:00
|
|
|
# GET /synapses/1.json
|
|
|
|
def show
|
|
|
|
@synapse = Synapse.find(params[:id])
|
|
|
|
|
|
|
|
#.authorize_to_show(@current)
|
2013-01-18 17:08:06 -05:00
|
|
|
|
2014-07-29 13:34:10 -04:00
|
|
|
#if not @synapse
|
|
|
|
# redirect_to root_url and return
|
|
|
|
#end
|
|
|
|
|
|
|
|
render json: @synapse
|
2013-01-18 17:08:06 -05:00
|
|
|
end
|
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
# POST /synapses
|
|
|
|
# POST /synapses.json
|
2012-10-09 20:23:45 -04:00
|
|
|
def create
|
2014-07-27 15:57:35 -04:00
|
|
|
@synapse = Synapse.new(params[:synapse])
|
|
|
|
|
2012-10-09 20:23:45 -04:00
|
|
|
respond_to do |format|
|
2014-07-27 15:57:35 -04:00
|
|
|
if @synapse.save
|
|
|
|
format.json { render json: @synapse, status: :created }
|
|
|
|
else
|
|
|
|
format.json { render json: @synapse.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2012-10-09 20:23:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-27 15:57:35 -04:00
|
|
|
# PUT /synapses/1
|
|
|
|
# PUT /synapses/1.json
|
2012-10-09 20:23:45 -04:00
|
|
|
def update
|
2014-07-27 15:57:35 -04:00
|
|
|
@synapse = Synapse.find(params[:id])
|
2013-01-05 23:37:24 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
2014-07-27 15:57:35 -04:00
|
|
|
if @synapse.update_attributes(params[:synapse])
|
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
|
|
|
format.json { render json: @synapse.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2013-01-05 23:37:24 -05:00
|
|
|
end
|
|
|
|
end
|
2012-10-09 20:23:45 -04:00
|
|
|
|
2012-12-21 18:07:13 -05:00
|
|
|
# DELETE synapses/:id
|
2012-10-09 20:23:45 -04:00
|
|
|
def destroy
|
2013-01-05 22:40:10 -05:00
|
|
|
@current = current_user
|
|
|
|
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
|
|
|
|
|
|
|
|
@synapse.mappings.each do |m|
|
2014-02-26 12:23:29 -08:00
|
|
|
|
|
|
|
m.map.touch(:updated_at)
|
2014-10-05 13:58:05 -04:00
|
|
|
|
2013-01-05 22:40:10 -05:00
|
|
|
m.delete
|
|
|
|
end
|
|
|
|
|
|
|
|
@synapse.delete if @synapse
|
2014-07-27 15:57:35 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2014-08-12 18:14:04 -04:00
|
|
|
format.json { head :no_content }
|
2014-07-27 15:57:35 -04:00
|
|
|
end
|
2012-10-09 20:23:45 -04:00
|
|
|
end
|
|
|
|
end
|