Define the actions of the presenter. The Carnival Gem has 4 default actions => [:show, :edit, :destroy, :new]
-
target
- [:page, :record]
- default_value: :record
- Define where the action will be rendered
-
show_func
- Define the function to be used to decide if the action wil be rendered or not
-
remote
- boolean
The parameters below are only valid for actions remotes:
-
method:
- Method used in the Request
- default_value: 'GET'
-
success
- Success Callback
- default_value: '[name_of_action]_success_callback'
-
error
- Error Callback
- default_value: '[name_of_action]_error_callback'
Define your custom action in the presenter
module Admin
class CompanyPresenter < Carnival::BaseAdminPresenter
field :id,
:actions => [:index, :show], :sortable => false,
:searchable => true,
:advanced_search => {:operator => :equal}
field :name,
:actions => [:index, :new, :edit, :show],
:searchable => true,
:advanced_search => {:operator => :like}
field :created_at, :actions => [:index, :show]
action :show
action :my_custom_action
end
endYou have to define a route with the name of the action
Define a action in the controller
module Admin
class CompaniesController < Carnival::BaseAdminController
layout "carnival/admin"
def your_action
id = params[:id]
...
end
def permitted_params
params.permit(admin_company: [:name])
end
end
endDefine your custom action in the presenter
module Admin
class CompanyPresenter < Carnival::BaseAdminPresenter
field :id,
:actions => [:index, :show], :sortable => false,
:searchable => true,
:advanced_search => {:operator => :equal}
field :name,
:actions => [:index, :new, :edit, :show],
:searchable => true,
:advanced_search => {:operator => :like}
field :created_at, :actions => [:index, :show]
action :show
action :my_remote_action,
:remote => true,
:method => 'POST'
end
endYou have to define a route with the name of the action
Define a action in the controller
module Admin
class CompaniesController < Carnival::BaseAdminController
layout "carnival/admin"
def remote_action
id = params[:id]
...
render :json => ...
end
def permitted_params
params.permit(admin_company: [:name])
end
end
endDefine Javascript callback functions for your Action
assets/companies.js
//Following Carnival convention for callback function names
function my_remote_action_success_callback(data){
Carnival.reloadTable();
}
function my_remote_action_error_callback(data){
Carnival.reloadTable();
}