Module: ControllerResources::Extension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/controller_resources/extension.rb
Overview
A single macro that combines all controller-level macros we use for the front-end of this application. Simply use the ‘resource :resource_name` macro in your controller class to make it work.
Example:
class ArtistsController < ApplicationController
resource :artist
def index
respond_with artists
end
def show
respond_with artist
end
end
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#current_resource ⇒ Object
A helper for engines like Pundit to configure the current authorizer policy for this controller.
-
#edit_params ⇒ Object
Omit any unpermitted parameters when editing or creating content.
-
#resource ⇒ Object
The resource object as made available to the controller.
-
#search_params ⇒ Object
Omit any unpermitted parameters when searching in collections.
Instance Method Details
#current_resource ⇒ Object
A helper for engines like Pundit to configure the current authorizer policy for this controller.
107 108 109 |
# File 'lib/controller_resources/extension.rb', line 107 def current_resource resource.model_class end |
#edit_params ⇒ Object
Omit any unpermitted parameters when editing or creating content. Permits all parameters when none are given in the resource block.
87 88 89 90 91 92 93 |
# File 'lib/controller_resources/extension.rb', line 87 def edit_params if resource.edit_params.any? params.require(resource.model_name).permit resource.edit_params else params.require(resource.model_name).permit! end end |
#resource ⇒ Object
The resource object as made available to the controller
98 99 100 101 |
# File 'lib/controller_resources/extension.rb', line 98 def resource fail Resource::NotConfiguredError unless self.class._resource.present? self.class._resource end |
#search_params ⇒ Object
Omit any unpermitted parameters when searching in collections. Permits all parameters when none are given in the resource block.
75 76 77 78 79 80 81 |
# File 'lib/controller_resources/extension.rb', line 75 def search_params if resource.search_params.any? params.permit resource.search_params else params.permit! end end |