0
從show view:我想通過顯示的消息的ID放棄行動和垃圾郵件。如何正確地將參數傳遞給控制器?
從索引視圖:我想通過檢查消息的ID放棄行動,並一次性垃圾。
但是我只能立即垃圾一條記錄,即使我檢查多個並從索引視圖提交。
我怎樣才能同時存檔1和2?
路線
match 'messages/discard(/:id)' => 'messages#discard', :via => :post , :as => :discard_messages
索引視圖
<%= form_tag(:action => discard, :via => 'post') 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(:id => m, :breadcrumb => @box) %></td>
</tr>
<% end %>
<%= submit_tag "discard", :class => 'btn' %>
<% end %>
放映視圖
<%= link_to 'Discard', discard_messages_path(@messages), :class => 'btn', :method => 'post' %>
控制器
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