Skip to content
Sergio Cambra edited this page Feb 27, 2024 · 11 revisions

Action 'show_search'

By default, ActiveScaffold has the action module :search, but it can be changed to :field_search, using conf.actions.swap :search, :field_search. Both modules use the action show_search to open the form.

Using 'search' module

These methods are called in the following order:

  1. search_authorized_filter called as before_action
    1. search_authorized? (or the method defined in conf.search.link.security_method if it's changed) is called to check the permission. If this method returns false, search_authorized_filter will raise ActiveScaffold::ActionNotAllowed.
  2. show_search
    1. respond_to_action, which will call the corresponding response method for show_search action and the requested format.

Then it will render these views:

  • search.html.erb (only for HTML request)
    • _search.html.erb

Using 'field_search' module

These methods are called in the following order:

  1. search_authorized_filter called as before_action
    1. search_authorized? (or the method defined in conf.field_search.link.security_method if it's changed) is called to check the permission. If this method returns false, search_authorized_filter will raise ActiveScaffold::ActionNotAllowed.
  2. show_search
    1. respond_to_action, which will call the corresponding response method for show_search action and the requested format.

Then it will render these views:

  • field_search.html.erb (only for HTML request)
    • _field_search.html.erb

Some of the columns defined in config.field_search.columns may be rendered in a subgroup which is collapsible and hidden by default, adding them to config.field_search.optional_columns too. When the form is open with a search active, they will be in the default group instead of the optional subgroup. The method visibles_and_hiddens can be overrided in a helper module to change the columns which are hidden, e.g. depending on params used to load the list.

Using both modules

Field_search module can be added without using swap, with conf.actions << :field_search. ActiveScaffold don't support having 2 action links for the same action with the same parameters, so the action link for field_search should use the parameter kind with the value :field_search:

conf.field_search.link.parameters = {kind: :field_search}

Then show_search will render the view or partial for search module, and show_search with kind=field_search will render the view or partial for field_search module.

Clone this wiki locally