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

66 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2012-10-10 00:23:45 +00:00
class SynapsesController < ApplicationController
include TopicsHelper
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)
2014-07-29 17:34:10 +00:00
#if not @synapse
# redirect_to root_url and return
#end
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
2014-07-27 19:57:35 +00:00
@synapse = Synapse.new(params[:synapse])
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])
respond_to do |format|
2014-07-27 19:57:35 +00:00
if @synapse.update_attributes(params[:synapse])
format.json { head :no_content }
else
format.json { render json: @synapse.errors, status: :unprocessable_entity }
end
end
end
2012-10-10 00:23:45 +00:00
# DELETE synapses/:id
2012-10-10 00:23:45 +00:00
def destroy
@current = current_user
@synapse = Synapse.find(params[:id]).authorize_to_delete(@current)
if @synapse
@synapse.mappings.each do |m|
m.map.touch(:updated_at)
m.delete
end
@synapse.delete
end
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
end