Module: Wallaby::ResourcesConcern
- Extended by:
- ActiveSupport::Concern
- Includes:
- Authorizable, Baseable, Configurable, Decoratable, Paginatable, Prefixable, Resourcable, Servicable
- Included in:
- ResourcesController
- Defined in:
- lib/concerns/wallaby/resources_concern.rb
Overview
Resources concern defining the controller behaviors for ResourcesController and other controllers that include itself
Constant Summary
Constants included from Prefixable
Instance Method Summary collapse
-
#create(location: -> { { action: :show, id: new_resource.id } }, **responder_options) {|format| ... } ⇒ Object
(also: #create!)
This is a resourceful action to create a record that user is allowed to.
-
#destroy(location: -> { { action: resource_id ? :index : :show } }, **responder_options) {|format| ... } ⇒ Object
(also: #destroy!)
This is a resourceful action to delete the record that user is allowed to.
-
#edit(**responder_options) {|format| ... } ⇒ Object
(also: #edit!)
This is a resourceful action to show the form to edit record that user is allowed to.
-
#home ⇒ Object
This is an action for landing page display.
-
#index(**responder_options) {|format| ... } ⇒ Object
(also: #index!)
This is a resourceful action to list records that user can access.
-
#new(**responder_options) {|format| ... } ⇒ Object
(also: #new!)
This is a resourceful action to show the form to create record that user is allowed to.
-
#show(**responder_options) {|format| ... } ⇒ Object
(also: #show!)
This is a resourceful action to display the record details that user is allowed to.
-
#update(location: -> { { action: :show } }, **responder_options) {|format| ... } ⇒ Object
(also: #update!)
This is a resourceful action to update the record that user is allowed to.
Methods included from Servicable
Methods included from Resourcable
#collection, #create_params, #current_model_class, #current_resources_name, #new_resource, #resource, #resource_id, #resource_params, #update_params
Methods included from Paginatable
#current_paginator, #paginate, #pagination_params_for
Methods included from Prefixable
Methods included from Decoratable
#current_decorator, #current_fields, #current_model_decorator, #decorate, #decorator_of, #extract
Methods included from Configurable
Methods included from Authorizable
#authorized?, #current_authorizer, #unauthorized?
Instance Method Details
#create(location: -> { { action: :show, id: new_resource.id } }, **responder_options) {|format| ... } ⇒ Object Also known as: create!
This is a template method that can be overridden by subclasses.
This is a resourceful action to create a record that user is allowed to.
If record is created successfully, user will be navigated to the record show page. Otherwise, the form will be shown again with error messages.
It can be customized as below in subclasses:
def create
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
create!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
def create
# NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
@resource = Product.new resource_params.merge(new_arrival: true)
if @resource.save
redirect_to helper.index_path(current_model_class)
else
render :new
end
end
172 173 174 175 176 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 172 def create(location: -> { { action: :show, id: new_resource.id } }, **, &block) . :create, new_resource current_servicer.create new_resource, create_params respond_with new_resource, .merge(location: location), &block end |
#destroy(location: -> { { action: resource_id ? :index : :show } }, **responder_options) {|format| ... } ⇒ Object Also known as: destroy!
This is a template method that can be overridden by subclasses.
This is a resourceful action to delete the record that user is allowed to.
It can be customized as below in subclasses:
def destroy
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
destroy!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
def destroy
# NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
@resource = Product.find_by_slug params[:id]
@resource.destroy
redirect_to helper.index_path(current_model_class)
end
327 328 329 330 331 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 327 def destroy(location: -> { { action: resource_id ? :index : :show } }, **, &block) . :destroy, resource current_servicer.destroy resource, {} respond_with resource, .merge(location: location), &block end |
#edit(**responder_options) {|format| ... } ⇒ Object Also known as: edit!
This is a template method that can be overridden by subclasses.
This is a resourceful action to show the form to edit record that user is allowed to.
It can be customized as below in subclasses:
def edit
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
edit!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
def edit
# NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
@resource = Product.find_by_slug params[:id]
end
243 244 245 246 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 243 def edit(**, &block) . :edit, resource respond_with resource, , &block end |
#home ⇒ Object
This is a template method that can be overridden by subclasses.
This is an action for landing page display. It does nothing more than rendering ‘home` template.
It can be replaced completely in subclasses as below:
def home
generate_dashboard_report
end
53 54 55 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 53 def home # do nothing end |
#index(**responder_options) {|format| ... } ⇒ Object Also known as: index!
This is a template method that can be overridden by subclasses.
This is a resourceful action to list records that user can access.
It can be customized as below in subclasses:
‘WARN: Please keep in mind that Wallaby User Interface requires index action to respond to csv and json format as well.`
def index
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
index!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
‘WARN: Please keep in mind that Wallaby User Interface requires index action to respond to csv and json format as well.`
def index
# NOTE: `@collection` will be used by the view, please ensure it is assigned, for example:
@collection = Product.all
respond_with @collection
end
93 94 95 96 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 93 def index(**, &block) . :index, current_model_class respond_with collection, , &block end |
#new(**responder_options) {|format| ... } ⇒ Object Also known as: new!
This is a template method that can be overridden by subclasses.
This is a resourceful action to show the form to create record that user is allowed to.
It can be customized as below in subclasses:
def new
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
new!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
def new
# NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
@resource = Product.new new_arrival: true
end
128 129 130 131 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 128 def new(**, &block) . :new, new_resource respond_with new_resource, , &block end |
#show(**responder_options) {|format| ... } ⇒ Object Also known as: show!
This is a template method that can be overridden by subclasses.
This is a resourceful action to display the record details that user is allowed to.
It can be customized as below in subclasses:
def show
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
show!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
def show
# NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
@resource = Product.find_by_slug params[:id]
end
208 209 210 211 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 208 def show(**, &block) . :show, resource respond_with resource, , &block end |
#update(location: -> { { action: :show } }, **responder_options) {|format| ... } ⇒ Object Also known as: update!
This is a template method that can be overridden by subclasses.
This is a resourceful action to update the record that user is allowed to.
If record is updated successfully, user will be navigated to the record show page. Otherwise, the form will be shown again with error messages.
It can be customized as below in subclasses:
def update
# do something before the original action
= {} # NOTE: see `responder_options` parameter for more details
# NOTE: this is better than using `super` in many ways, but choose the one that better fits your scenario
update!() do |format|
# NOTE: this block is for `respond_with` which works similar to `respond_to`
# customize response behaviour, or do something before the request is rendered
end
end
Otherwise, it can be replaced completely in subclasses:
def update
# NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
@resource = Product.find_by_slug params[:id]
@resource.assign_attributes resource_params.merge(new_arrival: true)
if @resource.save
redirect_to helper.index_path(current_model_class)
else
render :new
end
end
288 289 290 291 292 |
# File 'lib/concerns/wallaby/resources_concern.rb', line 288 def update(location: -> { { action: :show } }, **, &block) . :update, resource current_servicer.update resource, update_params respond_with resource, .merge(location: location), &block end |