アプリのユーザー モデル間の会話/メッセージにメールボックス ジェムを使用しています。スタック オーバーフローの大きな助けのおかげで、これはすべて正常に機能しています。管理者が発生しているすべての会話を表示できるように、セクションを設定しようとしています。
管理セクションにネストされた、会話用のコントローラーとビューを作成しました。インデックスページのすべての会話を次のように取り込みました。
def index
@admin_conversations = Conversation.all
end
これにより、期待どおり、すべての会話と、各会話を表示するためのリンクが一覧表示されました。
私が抱えている問題は、メールボックスの Gem が、current_user が参加している会話のみを current_user が表示できるように設定されていることです。そのため、会話の一部をクリックして (署名は管理者として)、コンテンツを表示できます。しかし、一部 (他のテスト ユーザー間) は表示されません。つまり、次のような例外がスローされます。
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 < 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
答えはおそらくかなりばかげたものですが、私はこれに慣れていません...
ありがとう