lamrin
lamrin

Reputation: 1441

rails fields_for error while adding :class inside select

in fields_for when i add :class=>"street" to text_field it works fine, where as when i add :class=>"zip" to select it is triggring error

<%= 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 %>

please, help to solve the issue

thanks

Upvotes: 1

Views: 1098

Answers (2)

TH Afridi
TH Afridi

Reputation: 432

Try using:

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

Upvotes: 0

Mischa
Mischa

Reputation: 43318

From the Rails API:

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

So, try this:

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

Upvotes: 4

Related Questions