In model specific form we use select method to display a select box and populate it with model data.
Example:
#controller
@location = Location.new()
#view
<%= select(:location,:city_id,City.all.collect {|p| [ p.name, p.id ] }) %>
or
<%= f.select(:city_id,City.all.collect {|p| [ p.name, p.id ] }) %>
where f is the form object.
select tag also takes optional arguments . They are :
:multiple - When set to true we can select more than one option.
:disabled - When set to true the select box will be disabled in the web page
:include_blank - When set to true an empty option will be created
:prompt - When a string is passed to this option it is displayed as option without any value in the web page.
0 Comment(s)