English 中文(简体)
铁路:投入数量可图
原标题: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 %>

它错了<代码>未界定的方法重复使用_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] ?

最佳回答

form_for(@model)?

因此,f.text_field(property)查询这一方法/property on @model

不妨将<代码>f.text_field(property)改为?

che

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag” rel=“nofollow” http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag

问题回答

暂无回答




相关问题
How do I escape the ERB tag in ERB

I have a simple fixture.yml file: label: body: "<%= variable %>" The issue is that the ERB code is parsed as part of loading the fixture, whereas I actually want the body to be literally "&...

how to use an array in form_for?

I ve got a user model which contains a field called, lets say, text1. In the users/new form I want to have 4 individual text boxes for this text1. In my model I will take values from these boxes and ...

Convert existing html.erb to Haml [closed]

I have a rails project, the views only consist with HTML.ERB files, my client wants to convert ERB to HAML. I have too many views file. It s taking a huge amount of time to convert file by file. So ...

alternatives for erb to make application.js dynamic

To make application.js more dynamic, I create javascript_controller and rename public/application.js to app/views/javascripts/application.js.erb But <%= … %> does not look very good in ...

ERB tag within link_to_function JavaScript call

I need to dynamically set which id a JavaScript call uses, as I have multiples rendered on each page, I m trying to use <p id="add_rider_link_section_<%= section.id %>"><%= ...

Print in ERB without <%=?

Sometimes it s more convenient to print in <%%>. How to do it in Rails?

热门标签