如果我在视图中检查多条记录,然后点击删除按钮,将调用丢弃操作。
现在我一次只能删除(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