ビューで複数のレコードをチェックしてから削除ボタンを押すと、破棄アクションが呼び出されます。
これで、一度に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