首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mailboxer Gem管理视图

Mailboxer Gem管理视图
EN

Stack Overflow用户
提问于 2014-02-07 14:18:27
回答 1查看 724关注 0票数 1

我正在应用程序中的用户模型之间使用mailboxer进行对话/消息。这一切都很好,多亏了堆栈溢出方面的一些很好的帮助。我现在正在尝试设置一个部分,这样管理员就可以查看正在发生的所有会话。

我已经为会话创建了一个控制器和视图,嵌套在我的管理部分中。我在索引页面上输入了所有的对话:

代码语言:javascript
复制
 def index
    @admin_conversations = Conversation.all
  end

这列出了所有的对话,和一个链接,以显示每个对话,如预期。

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

代码语言:javascript
复制
Couldn't find Conversation with id=5 [WHERE "notifications"."type" = 'Message' AND "receipts"."receiver_id" = 35 AND "receipts"."receiver_type" = 'User']

如何在我的管理控制器中定义方法,以便管理员能够看到所有的东西?

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

代码语言:javascript
复制
can :manage, Conversation

...so,这不是一个正常的授权问题。

这是我的会话控制器:

代码语言:javascript
复制
class ConversationsController < ApplicationController
  authorize_resource
  helper_method :mailbox, :conversation


  def create
    recipient_emails = conversation_params(:recipients).split(',')
    recipients = User.where(email: recipient_emails).all

    conversation = current_user.
      send_message(recipients, *conversation_params(:body, :subject)).conversation

    redirect_to :back, :notice => "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

答案可能很愚蠢,但我对此并不熟悉.

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-07 15:44:29

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

mailbox.conversations是限制您与当前用户对话的因素。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21630044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档