Tag: mailboxer

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, […]

外国人 – 删除外键

我想在我的rails 4 app中使用mailboxer。 当我尝试部署数据库时出现问题。 创建邮箱会话表时出错,该表在通知表中具有依赖关系。 我正在尝试删除通知对话的外键。 我创建了一个迁移说: change_table :notifications do |t| t.remove_foreign_key :conversations 然而,rake中止并说外键不存在。 rake aborted! An error has occurred, this and all later migrations canceled: PG::UndefinedObject: ERROR: constraint “notifications_conversation_id_fk” of relation “notifications” does not exist 我的架构包括:add_foreign_key“notifications”,“conversation”,name:“notifications_on_conversation_id” 我试图挖掘db:migrate:down创建邮箱的原始迁移,但也收到错误,说’找不到命令’。 有人可以帮忙吗? 谢谢。

Ruby on Rails – ActiveRecord ::关系计数方法错了?

我正在编写一个应用程序,允许用户发送有关“优惠”的消息。 我以为我会节省一些工作并使用Mailboxer gem。 我正在遵循RSpec的测试驱动开发方法。 我正在编写一个测试,确保每个优惠只允许一次Conversation 。 优惠belongs_to两个不同的用户(提出优惠的用户和收到优惠的用户)。 这是我的失败测试: describe “after a message is sent to the same user twice” do before do 2.times { sending_user.message_user_regarding_offer! offer, receiving_user, random_string } end specify { sending_user.mailbox.conversations.count.should == 1 } end 因此,在测试运行之前,用户sending_user向sending_user发送两次消息。 message_user_regarding_offer! 看起来像这样: def message_user_regarding_offer! offer, receiver, body conversation = offer.conversation if conversation.nil? self.send_message(receiver, body, offer.conversation_subject) else self.reply_to_conversation(conversation, […]