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 %>
请帮助解决问题
感谢
答案 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" %>