我正在创建一个调查,并且有一堆:movie_1
通过命名的列:movie_5
,我想循环遍历这些列以在我的表单中创建一个表格。最好的方法是什么?
到目前为止,我已经开始如下,但无法弄清楚如何格式化循环。
调查.rb模型
attr_accessible :movie_1, :movie_2, :movie_3, :movie_4, :movie_5
MOVIES = ["Rocky", "Wayne's World", "The Godfather", "Alien", "Toy Story"]
new.html.erb调查表
<%= form_for @survey do |f|
<table>
<tr>
<th>Movie Name</th>
<th>Rating</th>
</r>
<% 5.times.each do |n| %>
<tr>
<th><%= f.label Survey::MOVIES[n] %></th> # how can I loop through the MOVIES array?
<th><%= f.text_field :movie_n %></th> # how can I loop through the different columns?
</tr>
<% end %>
</table>
<% end %>