0

I wrote a form that generates a text input for each property.
The list of properties is configurable by the customer.

<% properties = ["refractivity_at_2kHz", "refractivity_at_5kHz"] %>

<% properties.each do |property| %>
  <div class="property">
    <%= f.label property %>
    <%= f.text_field property %>
  </div>
<% end %>

It fails with the error undefined method refractivity_at_2kHz.

What is the usual solution for this problem?

Should I add an array to my model, and use f.text_field myarray[property] ?

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373

1 Answers1

1

Is it a form_for(@model)?

Because then f.text_field(property) looks for that method/property on @model.

May be you want to change f.text_field(property) into text_field_tag(property)[1]

cheers

[1] http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag

krichard
  • 3,699
  • 24
  • 34