0

I have been facing some problems with mailboxer gem . The reply and trash specifically , the messages are replied to and when selected to delete are sent to trash too but i haven't able to successfully redirect it to the inbox after it does so . I always keep getting the error "Cannot find user with id" Following is my controller code for the trash part -

  def trash

      conversation = Conversation.find(params[:id])

      beta = current_userA || current_userB

         case beta

          when current_userA

            conversation.move_to_trash(current_userA)

            # redirect_to :conversations

          when current_userB

           conversation.move_to_trash(current_userB)

           # redirect_to :conversations

         end



    respond_to do |format|      
       format.html { redirect_to conversation_path, notice: 'Conversation successfully trashed.' }        
    end

end

Logs

Started GET "/conversations/36" for 127.0.0.1 at 2014-08-28 10:19:56 +0530
Processing by ConversationsController#show as HTML

  Parameters: {"id"=>"36"}

  Message Load (0.5ms)  SELECT "notifications".* FROM "notifications" WHERE "notifications"."type" IN ('Message') AND "notifications"."id" = $1 LIMIT 1  [["id", "36"]]

  Conversation Load (0.4ms)  SELECT "conversations".* FROM "conversations" WHERE "conversations"."id" = 34 LIMIT 1

Completed 404 Not Found in 4ms

ActiveRecord::RecordNotFound (Couldn't find userA without an ID):

  app/controllers/conversations_controller.rb:160:in `show'


  Rendered /usr/local/rvm/gems/ruby-1.9.3-p545/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)

  Rendered /usr/local/rvm/gems/ruby-1.9.3-p545/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)

  Rendered /usr/local/rvm/gems/ruby-1.9.3-p545/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.7ms)

Updated Log

After changing redirect_to conversation with redirect_to conversations

Started POST "/conversations/38/trash" for 127.0.0.1 at 2014-08-28 12:29:16 +0530
Processing by ConversationsController#trash as HTML
  Parameters: {"authenticity_token"=>"CuXzMKNmD87qvfOuer4uhyTdysFS/5NxtfMZU3/Y5j0=", "id"=>"38"}
  Conversation Load (0.4ms)  SELECT "conversations".* FROM "conversations" WHERE "conversations"."id" = $1 LIMIT 1  [["id", "38"]]
  Filmmaker Load (0.7ms)  SELECT "userA".* FROM "userA" WHERE "userA"."id" = 67 LIMIT 1
  Receipt Load (0.8ms)  SELECT "receipts".* FROM "receipts" INNER JOIN "notifications" ON "notifications"."id" = "receipts"."notification_id" AND "notifications"."type" IN ('Message') WHERE "notifications"."conversation_id" = 38 AND "receipts"."receiver_id" = 67 AND "receipts"."receiver_type" = 'userA'
  SQL (11.3ms)  UPDATE "receipts" SET "trashed" = 't' WHERE (id = 82 )
  User Load (29.7ms)  SELECT "users".* FROM "users" 
Completed 500 Internal Server Error in 110ms

NameError (undefined local variable or method `conversations' for #<ConversationsController:0x10961634>):
  app/controllers/conversations_controller.rb:101:in `block (2 levels) in trash'
  app/controllers/conversations_controller.rb:100:in `trash'

Please do advice what i am doing wrong , i have been at it since a day and i haven't found any solution to it .Needless to say , userA and userB are both different devise users. Any suggestions on it is most welcome .

  • Why are redirects commented out? What is the exact exception message (please COPY & PASTE it)? In which line do you get an error, I don't se any `User.find` in here...? – Mike Szyndel Aug 27 '14 at 14:28
  • @Michal I will definitely post the error tomorrow as currently I don't have access to my machine . Until then can you please post your answer where exactly should I write the user.find code –  Aug 27 '14 at 15:21
  • I can't give you an answer without looking at the code. And the code above is incomplete apparently. – Mike Szyndel Aug 27 '14 at 16:00
  • @MichalSzyndel This is the controller code for trash , please do let me know what else do you need . –  Aug 28 '14 at 04:42
  • @MichalSzyndel - Posting the logs for the action –  Aug 28 '14 at 04:54
  • you realise where this redirects to? `format.html { redirect_to :conversation }` – Mike Szyndel Aug 28 '14 at 06:34
  • yes , it redirects to the conversations index where basically the inbox is . –  Aug 28 '14 at 06:34
  • should i post the show method @MichalSzyndel ? –  Aug 28 '14 at 06:35
  • No, it redirects to _a_ conversation, without id specified. It should say `redirect_to :conversations`. It would be a good practice for you to write `redirect_to conversations_path` so if you make a typo, it will warn you. – Mike Szyndel Aug 28 '14 at 06:40
  • Let me try the same and update you –  Aug 28 '14 at 06:44
  • @MichalSzyndel I added in the code and updated the same as suggested by Avishek below but it still shows the same error . –  Aug 28 '14 at 06:47
  • @MichalSzyndel - Please see the updated log , stumbled upon a new error which i think is the cause . –  Aug 28 '14 at 07:03

1 Answers1

0

Try to use a path in redirect, which you can get from rake_routes. Maybe the example given below will work for you.

respond_to do |format|
    format.html { redirect_to inbox_path, notice: 'Conversation successfully trashed.' }    
end