在运行每个用户时为每个用户创建一个form_tag

时间:2012-01-19 22:47:48

标签: ruby-on-rails ruby

我正在尝试创建一个反馈表单,其中每个学生可以列出2个兴趣。

但是,使用下面的代码,它仅识别最后一名学生的interest_1和interest_2,并将值映射到所有学生,而不是每个学生的不同值。任何人都可以了解如何为每个学生制定兴趣_1和兴趣_2?

<%= form_tag feedback_send_path, :method => 'post' do %>
  <% @course.students.each do |student| %>
    <%= avatar_for(student, :photo_size => :thumb_small, :class => 'notBig', :size => '50x50') %>
    <%= link_to student.name, user_path(student.id), :class => "profile-link" %>
    <%= text_area_tag 'interest_1', '', :class => 'feedback-form', :placeholder => "Wants to teach..." %>
    <%= text_area_tag 'interest_2', '', :class => 'feedback-form', :placeholder => "Wants to learn..." %>
  <% end %>
<%= submit_tag "Submit", :class => "send-message-button" %>
<% end %>

`

1 个答案:

答案 0 :(得分:0)

而不是

<%= text_area_tag 'interest_1', '', :class => 'feedback-form', :placeholder => "Wants to teach..." %>
    <%= text_area_tag 'interest_2', '', :class => 'feedback-form', :placeholder => "Wants to learn..." %>

使用

<%= text_area_tag 'interest_1[]', '', :class => 'feedback-form', :placeholder => "Wants to teach..." %>
    <%= text_area_tag 'interest_2[]', '', :class => 'feedback-form', :placeholder => "Wants to learn..." %>

然后看看你的params Hash!