Class: Spree::Api::ResourceController Deprecated
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::ResourceController
- Defined in:
- app/controllers/spree/api/resource_controller.rb
Overview
Deprecated.
Inherit directly from Spree::Api::BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.inherited(klass) ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/controllers/spree/api/resource_controller.rb', line 7 def self.inherited(klass) Spree::Deprecation.warn <<~MSG Spree::Api::ResourceController is deprecated. Please, copy any logic you need and inherit directly from Spree::Api::BaseController. MSG super end |
Instance Method Details
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/spree/api/resource_controller.rb', line 39 def create :create, model_class @object = model_class.new(permitted_resource_params) instance_variable_set("@#{object_name}", @object) if @object.save respond_with(@object, status: 201, default_template: :show) else invalid_resource!(@object) end end |
#destroy ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/spree/api/resource_controller.rb', line 62 def destroy :destroy, @object destroy_result = if @object.respond_to?(:discard) @object.discard else @object.destroy end if destroy_result respond_with(@object, status: 204) else invalid_resource!(@object) end rescue ActiveRecord::DeleteRestrictionError render "spree/api/errors/delete_restriction", status: 422 end |
#index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/spree/api/resource_controller.rb', line 15 def index collection_scope = model_class.accessible_by(current_ability) if params[:ids] ids = params[:ids].split(",").flatten collection_scope = collection_scope.where(id: ids) else collection_scope = collection_scope.ransack(params[:q]).result end @collection = paginate(collection_scope) instance_variable_set("@#{controller_name}", @collection) respond_with(@collection) end |
#new ⇒ Object
34 35 36 37 |
# File 'app/controllers/spree/api/resource_controller.rb', line 34 def new :new, model_class respond_with(model_class.new) end |
#show ⇒ Object
30 31 32 |
# File 'app/controllers/spree/api/resource_controller.rb', line 30 def show respond_with(@object) end |
#update ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/spree/api/resource_controller.rb', line 52 def update :update, @object if @object.update(permitted_resource_params) respond_with(@object, status: 200, default_template: :show) else invalid_resource!(@object) end end |