-
Notifications
You must be signed in to change notification settings - Fork 256
Adding new document actions
cbeer edited this page Nov 13, 2014
·
9 revisions
In your CatalogController
, you need to register an action using add_action
. If the action will receive form data from a POST
request, you can also register a callback for handling that request. Optionally, the POST
params can be validated using a helper method.
class CatalogController
include Blacklight::Catalog
...
# Register a new action called "email".
# On a POST request, validate the params using the `#validate_email_params` method
# and process the request using `#email_action`.
add_action :email, :email_action, validator: :validate_email_params
def validate_email_params
# validate that the posted params are suitable for the action
end
def email_action documents
# send an email with the attached documents
end
...
end
The action name is, by convention, the name of the template to render for that action. In this case, we may render the catalog/email.html.erb
template when the action is selected. This template provides a form, which, when submitted, will trigger the email_action
method and will render the catalog/email_success.html.erb
template.