rails fields_for在添加时出错:class inside select

时间:2011-04-19 12:54:22

标签: ruby-on-rails

fields_for中的{p>当我将:class=>"street"添加到text_field时,它可以正常工作 当我添加:class=>"zip"来选择它是触发错误

<%= form_for @person do |person_form| %>
    <%= person_form.fields_for :address do |address_fields| %>
      Street  : <%= address_fields.text_field :street, :class=>"street" %>
      Zip code: <%= address_fields.select :zip_code, :class=>"zip", options_for_select(@zip.to_a) %>
    <% end %>
  <% end %>

请帮助解决问题

感谢

2 个答案:

答案 0 :(得分:4)

来自Rails API

select(object, method, choices, options = {}, html_options = {})

所以,试试这个:

Zip code: <%= address_fields.select :zip_code, 
               options_for_select(@zip.to_a), {}, { :class => "zip" }
          %>

答案 1 :(得分:0)

尝试使用:

Zip code: <%= address_fields.select :zip_code, options_for_select(@zip.to_a),:class=>"zip" %>