From ccfba03fdb1ed5a858f3573f84026ee90c0b7c77 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 11 Mar 2016 17:26:54 +1100 Subject: [PATCH] clean up duplicate code --- app/controllers/api/mappings_controller.rb | 8 -------- app/controllers/api/maps_controller.rb | 8 -------- app/controllers/api/restful_controller.rb | 8 ++++++++ app/controllers/api/synapses_controller.rb | 8 -------- app/controllers/api/tokens_controller.rb | 10 +--------- app/controllers/api/topics_controller.rb | 8 -------- 6 files changed, 9 insertions(+), 41 deletions(-) diff --git a/app/controllers/api/mappings_controller.rb b/app/controllers/api/mappings_controller.rb index 83892b9a..426c9dbe 100644 --- a/app/controllers/api/mappings_controller.rb +++ b/app/controllers/api/mappings_controller.rb @@ -1,11 +1,3 @@ class Api::MappingsController < API::RestfulController - def create - raise CanCan::AccessDenied.new unless current_user.is_logged_in? - instantiate_resouce - resource.user = current_user - create_action - respond_with_resource - end - end diff --git a/app/controllers/api/maps_controller.rb b/app/controllers/api/maps_controller.rb index 2f86d254..7b805280 100644 --- a/app/controllers/api/maps_controller.rb +++ b/app/controllers/api/maps_controller.rb @@ -1,11 +1,3 @@ class Api::MapsController < API::RestfulController - def create - raise CanCan::AccessDenied.new unless current_user.is_logged_in? - instantiate_resouce - resource.user = current_user - create_action - respond_with_resource - end - end diff --git a/app/controllers/api/restful_controller.rb b/app/controllers/api/restful_controller.rb index 8289583d..d56783a0 100644 --- a/app/controllers/api/restful_controller.rb +++ b/app/controllers/api/restful_controller.rb @@ -1,6 +1,14 @@ class API::RestfulController < ActionController::Base snorlax_used_rest! + def create + raise CanCan::AccessDenied.new unless current_user.is_logged_in? + instantiate_resouce + resource.user = current_user + create_action + respond_with_resource + end + def show load_resource raise AccessDenied.new unless resource.authorize_to_show(current_user) diff --git a/app/controllers/api/synapses_controller.rb b/app/controllers/api/synapses_controller.rb index de435df3..f133ffd0 100644 --- a/app/controllers/api/synapses_controller.rb +++ b/app/controllers/api/synapses_controller.rb @@ -1,11 +1,3 @@ class Api::SynapsesController < API::RestfulController - def create - raise CanCan::AccessDenied.new unless current_user.is_logged_in? - instantiate_resouce - resource.user = current_user - create_action - respond_with_resource - end - end diff --git a/app/controllers/api/tokens_controller.rb b/app/controllers/api/tokens_controller.rb index 2b2ff8df..cc54e531 100644 --- a/app/controllers/api/tokens_controller.rb +++ b/app/controllers/api/tokens_controller.rb @@ -1,13 +1,5 @@ class Api::TokensController < API::RestfulController - - def create - raise CanCan::AccessDenied.new unless current_user.is_logged_in? - instantiate_resouce - resource.user = current_user - create_action - respond_with_resource - end - + def my_tokens raise CanCan::AccessDenied.new unless current_user.is_logged_in? instantiate_collection page_collection: false, timeframe_collection: false diff --git a/app/controllers/api/topics_controller.rb b/app/controllers/api/topics_controller.rb index ded6a5e6..f3633544 100644 --- a/app/controllers/api/topics_controller.rb +++ b/app/controllers/api/topics_controller.rb @@ -1,11 +1,3 @@ class Api::TopicsController < API::RestfulController - def create - raise CanCan::AccessDenied.new unless current_user.is_logged_in? - instantiate_resouce - resource.user = current_user - create_action - respond_with_resource - end - end