Skip to content

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

By convention, the action name is used to determine the route name for the action. For this email action, Blacklight will link to email_catalog_path.

The action will render the template 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.

Clone this wiki locally