天天看點

Rails 的form helper select的幾個參數

<%= select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {:prompt => 'Select', :include_blank => true, :selected => ''}, :style => "width:100px" %>
           
select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
           

=》

<select name="album[][genre]" id="album__genre">
    <option value="rap">rap</option>
    <option value="rock">rock</option>
    <option value="country">country</option>
  </select>
           
select("post", "category", Post::CATEGORIES, {:disabled => 'restricted'})
           
<select name="post[category]">
    <option></option>
    <option>joke</option>
    <option>poem</option>
    <option disabled="disabled">restricted</option>
  </select>
           

官網[url]http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html[/url]

資源參考:

[url]http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select[/url]