我创建了调查,并有一堆命名的列的:movie_1通过:movie_5,我想通过做一个表,我的形式循环.这样做的最佳方法是什么?
到目前为止,我已经开始如下,但无法弄清楚如何格式化循环.
survey.rb模型
attr_accessible :movie_1, :movie_2, :movie_3, :movie_4, :movie_5
MOVIES = ["Rocky", "Wayne's World", "The Godfather", "Alien", "Toy Story"]
Run Code Online (Sandbox Code Playgroud)
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 %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1051 次 |
| 最近记录: |