instance method
select
Ruby on Rails 2.3.18
Since v2.2.3Signature
select(object, method, choices, options = {}, html_options = {})
Create a select tag and a series of contained option tags for the provided object and method. The option currently held by the object will be selected, provided that the object is available. See options_for_select for the required format of the choices parameter.
Example with @post.person_id => 1:
select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })
could become:
<select name="post[person_id]"> <option value=""></option> <option value="1" selected="selected">David</option> <option value="2">Sam</option> <option value="3">Tobias</option> </select>
This can be used to provide a default set of options in the standard way: before rendering the create form, a new model instance is assigned the default options and bound to @model_name. Usually this model is not saved to the database. Instead, a second model object is created when the create request is received. This allows the user to submit a form page more than once with the expected results of creating multiple records. In addition, this allows a single partial to be used to generate form inputs for both edit and create forms.
By default, post.person_id is the selected option. Specify :selected => value to use a different selection or :selected => nil to leave all options unselected. Similarly, you can specify values to be disabled in the option tags by specifying the :disabled option. This can either be a single value or an array of values to be disabled.
Parameters
-
objectreq -
methodreq -
choicesreq -
optionsopt = {} -
html_optionsopt = {}
Source
# File actionpack/lib/action_view/helpers/form_options_helper.rb, line 127
def select(object, method, choices, options = {}, html_options = {})
InstanceTag.new(object, method, self, options.delete(:object)).to_select_tag(choices, options, html_options)
end
Defined in actionpack/lib/action_view/helpers/form_options_helper.rb line 127
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::FormOptionsHelper