| Module | MetaSearch::Helpers::FormBuilder |
| In: |
lib/meta_search/helpers/form_builder.rb
|
Behaves almost exactly like the select method, but instead of generating a select tag, generates MetaSearch::Checks. These consist of two attributes, box and label, which are (unsurprisingly) the HTML for the check box and the label. Called without a block, this method will return an array of check boxes. Called with a block, it will yield each check box to your template.
*Parameters:*
*Examples:*
Simple formatting:
<h4>How many heads?</h4>
<ul>
<% f.checks :number_of_heads_in,
[['One', 1], ['Two', 2], ['Three', 3]], :class => 'checkboxy' do |check| %>
<li>
<%= check.box %>
<%= check.label %>
</li>
<% end %>
</ul>
This example will output the checkboxes and labels in an unordered list format.
Grouping:
Chain in_groups_of(<num>, false) on checks like so:
<h4>How many heads?</h4>
<p>
<% f.checks(:number_of_heads_in,
[['One', 1], ['Two', 2], ['Three', 3]],
:class => 'checkboxy').in_groups_of(2, false) do |checks| %>
<% checks.each do |check| %>
<%= check.box %>
<%= check.label %>
<% end %>
<br />
<% end %>
</p>
Just like checks, but this time you can pass in a collection, value, and text method, as with collection_select.
Example:
<% f.collection_checks :head_sizes_in, HeadSize.all,
:id, :name, :class => 'headcheck' do |check| %>
<%= check.box %> <%= check.label %>
<% end %>
Like other form_for field methods (text_field, hidden_field, password_field) etc, but takes a list of hashes between the method parameter and the trailing option hash, if any, to specify a number of fields to create in multiparameter fashion.
Each hash must contain a :field_type option, which specifies a form_for method, and may contain an optional :type_cast option, with one of the typical multiparameter type cast characters. Any remaining options will be merged with the defaults specified in the trailing option hash and passed along when creating that field.
For example…
<%= f.multiparameter_field :moderations_value_between,
{:field_type => :text_field, :class => 'first'},
{:field_type => :text_field, :type_cast => 'i'},
:size => 5 %>
…will create the following HTML:
<input class="first" id="search_moderations_value_between(1)" name="search[moderations_value_between(1)]" size="5" type="text" /> <input id="search_moderations_value_between(2i)" name="search[moderations_value_between(2i)]" size="5" type="text" />
As with any multiparameter input fields, these will be concatenated into an array and passed to the attribute named by the first parameter for assignment.
Creates a sort link for the MetaSearch::Builder the form is created against. Useful shorthand if your results happen to reside in the context of your form_for block. Sample usage:
<%= f.sort_link :name %> <%= f.sort_link :name, 'Company Name' %> <%= f.sort_link :name, :class => 'name_sort' %> <%= f.sort_link :name, 'Company Name', :class => 'company_name_sort' %>