在特定操作后重定向

时间:2014-08-27 13:07:18

标签: ruby-on-rails ruby-on-rails-3 devise ruby-on-rails-3.2 mailboxer

我一直面临着邮箱gem的一些问题。特别是回复和垃圾邮件,邮件被回复,当被选中删除时也被发送到垃圾箱,但我无法成功将其重定向到收件箱。我一直收到错误“无法找到具有id的用户”以下是我的垃圾部分的控制器代码 -

  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

日志

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)

更新日志

使用redirect_to conversation更改redirect_to对话后

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'

请告诉我我做错了什么,我已经有一天了,而且我还没有找到任何解决方案。不用说,userA和userB都是不同的设计用户。对此有任何建议是非常受欢迎的。

1 个答案:

答案 0 :(得分:0)

尝试在重定向中使用path,您可以从rake_routes获取。也许下面给出的例子对你有用。

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