Mailboxer Gem,管理员视图

我在我的应用程序中的User模型之间使用mailboxer gem进行对话/消息。 这一切都运行正常,这要归功于堆栈溢出方面的一些帮助。 我现在正在尝试设置一个部分,以便管理员可以查看正在发生的所有对话。

我已经在我的管理部分中创建了一个控制器和对话视图。 我已经在索引页面上完成了所有对话:

def index @admin_conversations = Conversation.all end 

这已按预期列出了所有会话以及显示每个会话的链接。

我遇到的问题是,邮箱Gem设置为只允许current_user查看current_user参与的对话。所以我可以点击一些对话,(签名为管理员)并查看内容,但有些(在其他测试用户之间)我看不到它会引发exception,例如:

 Couldn't find Conversation with id=5 [WHERE "notifications"."type" = 'Message' AND "receipts"."receiver_id" = 35 AND "receipts"."receiver_type" = 'User'] 

如何在管理控制器中定义方法,以便管理员可以看到所有内容?

我目前正在使用cancan并允许我拥有的所有3个用户角色(管理员,客户端和供应商),如下所示:

 can :manage, Conversation 

…所以这不是正常的授权问题。

这是我的对话控制器:

 class ConversationsController  "Message Sent! You can view it in 'My Messages'." end def count current_user.mailbox.receipts.where({:is_read => false}).count(:id, :distinct => true).to_s end def reply current_user.reply_to_conversation(conversation, *message_params(:body, :subject)) redirect_to conversation end def trash conversation.move_to_trash(current_user) redirect_to :conversations end def untrash conversation.untrash(current_user) redirect_to :conversations end private def mailbox @mailbox ||= current_user.mailbox end def conversation @conversation ||= mailbox.conversations.find(params[:id]) end def conversation_params(*keys) fetch_params(:conversation, *keys) end def message_params(*keys) fetch_params(:message, *keys) end def fetch_params(key, *subkeys) params[key].instance_eval do case subkeys.size when 0 then self when 1 then self[subkeys.first] else subkeys.map{|k| self[k] } end end end end 

答案可能是非常愚蠢的,但我是新手……

谢谢

在您的对话方法中,您的调用mailbox.conversations.find(params[:id])

mailbox.conversations限制了当前用户的会话。

试试Conversation.find(params[:id])