2012-07-10 24 views
0

我正在使用Mailboxer寶石。如何一次切換多個記錄的標誌?

行被選中,並且視圖正在傳遞多個ID,但是此操作僅在接收到參數時拋出第一個ID#的記錄。

我需要做什麼來清除與參數中傳遞的ID相對應的所有記錄?

參數

{"utf8"=>"✓", 
"authenticity_token"=>"35UoVt+dvwrGAgg+KZjn8jCZjlkdPj1ktCg5ASyCI4w=", 
"checked_items"=>{"15"=>"15", 
"14"=>"14"}, 
"commit"=>"Trash All Checked"} 

行動

def discard 

    conversation = Conversation.find_by_id(params[:checked_items].keys) 

    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 
+2

而不是find_by_id使用find_all_by_id,你會得到所有的對話,然後逐個垃圾。 – Arun 2012-07-10 05:48:54

+0

謝謝!它完全有效! – MKK 2012-07-10 06:11:46

回答

0

相反find_by_id使用find_all_by_id,你會得到所有的談話垃圾,然後一個接一個。

相關問題