Module: Searchgasm::Helpers::Form

Defined in:
lib/searchgasm/helpers/form.rb

Overview

Form Helper

Enables you to use form_for and fields_for just like you do with an ActiveRecord object.

Examples

Let’s assume @search is searching Address

form_for(@search) # is equivalent to form_for(:search, @search, :url => addresses_path)
form_for([@current_user, @search]) # is equivalent to form_for(:search, @search, :url => user_addresses_path(@current_user))
form_for([:admin, @search]) # is equivalent to form_for(:search, @search, :url => admin_addresses_path)
form_for(:search, @search, :url => whatever_path)

The goal was to mimic how ActiveRecord objects are treated. You can also pass a Searchgasm::Conditions::Base object as well and it will function the same way.

Automatic hidden fields generation

If you pass a Searchgasm::Search::Base object it automatically adds the :order_by, :order_as, :priority_order_by, :priority_order_as, and :per_page hidden fields. This is done so that when someone creates a new search, their options are remembered. It keeps the search consistent and is much more user friendly. If you want to override this you can pass the following options or you can set this up in your configuration, see Searchgasm::Config for more details.

Lastly some light javascript is added to the “onsubmit” action. You will notice that the control type helpers add in hidden fields in the page, as a way to declare its “state”. The form finds these elements, gets their values and updates its hidden fields so that the correct values will be submitted during the search. The end result is having these search options remembered.

Options

  • :hidden_fields — Array, a list of hidden fields to include. Defaults to [:order_by, :order_as, :per_page]. Pass false, nil, or a blank array to not include any.

Defined Under Namespace

Modules: Base, FormBuilder, Shared