Rails: Form with configurable number of inputs
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] ?
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
加载中,请稍侯......
精彩评论