2012-01-19 81 views
0

我正在嘗試創建一個反饋表單,每個學生可以列出2個興趣。當每個用戶運行每個用戶時,爲每個用戶制定一個form_tag

但是,通過下面的代碼,它僅識別上一個學生的interest_1和interest_2,並將這些值映射到所有學生,而不是每個學生的不同值。任何人都可以瞭解如何針對每個學生製作interest_1和interest_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 %> 

`

回答

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哈希!

+0

現在它爲我提供了每個用戶的所有值,如用戶1感興趣[用戶1的興趣1,用戶1的興趣2,用戶2的興趣1,用戶2的興趣2,興趣1用戶3,用戶3的興趣2],而不是每個用戶一行。 –

+0

是的,所以有任何開放的問題? – davidb