0
如果我查看我的視圖中的多個記錄,然後點擊刪除按鈕, 丟棄操作將被調用。如何使控制器的動作可以調整爲多個散列參數
現在我只能一次性刪除(untrash)1條記錄。 即使我檢查多個記錄,爲什麼我不能一次刪除所有這些記錄?
視圖
<%= form_tag(:action => discard, :via => 'put') do %>
<% @messages.each do |m| %>
<tr>
<td><%= check_box_tag "id",m.id %></td>
<td><%= m.last_message.id %></td>
<td><%= 'unread' if m.is_unread?(current_user) %></td>
<td><%= m.last_message.created_at.to_s(:jp) %></td>
<td><%= m.last_sender.username %></td>
<td><%= link_to m.subject, show_messages_path(m) %></td>
</tr>
<% end %>
<%= submit_tag "delete", :class => 'btn' %>
<% end %>
控制器
def discard
conversation = Conversation.find_all_by_id(params[:id])
if conversation
current_user.trash(conversation)
flash[:notice] = "Message sent to trash."
else
conversations = Conversation.find(params[:conversations])
conversations.each { |c| current_user.trash(c) }
flash[:notice] = "Messages sent to trash."
end
redirect_to :back
end
路由
match 'messages/discard(/:id)' => 'messages#discard' , :as => :discard_messages