简体   繁体   English

Mailboxer Gem Rails 4-创建视图

[英]Mailboxer Gem Rails 4 - Creating the Views

I'm having difficulty implementing the views for the Mailboxer gem in Rails 4. So far I have it setup where users can message other users but I don't have anyway for users to see their conversations. 我在Rails 4中实现Mailboxer gem的视图时遇到困难。到目前为止,我已经安装了它,用户可以在其中向其他用户发送消息,但是我仍然无法让用户看到他们的对话。

I was getting this error even after I created the partial view: (Trying to copy the views from the example app) 即使创建了部分视图,我仍然收到此错误:(尝试从示例应用程序复制视图)

ActionView::Template::Error (Missing partial mailboxer/conversations/_conversation with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:

So i ended up just deleting the views. 所以我最后只是删除视图。 This is what happens when I send a message: 当我发送消息时会发生以下情况:

2.1.1 :004 > User.first.send_message(User.last, "body", "subject")
  User Load (0.3ms)  SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1
  User Load (0.2ms)  SELECT  "users".* FROM "users"   ORDER BY "users"."id" DESC LIMIT 1
   (0.1ms)  begin transaction
  SQL (0.4ms)  INSERT INTO "mailboxer_conversations" ("created_at", "subject", "updated_at") VALUES (?, ?, ?)  [["created_at", "2014-06-24 17:51:36.131962"], ["subject", "subject"], ["updated_at", "2014-06-24 17:51:36.131962"]]
  SQL (0.2ms)  INSERT INTO "mailboxer_notifications" ("body", "conversation_id", "created_at", "sender_id", "sender_type", "subject", "type", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?)  [["body", "body"], ["conversation_id", 3], ["created_at", "2014-06-24 17:51:36.131962"], ["sender_id", 1], ["sender_type", "User"], ["subject", "subject"], ["type", "Mailboxer::Message"], ["updated_at", "2014-06-24 17:51:36.131962"]]
  SQL (0.2ms)  INSERT INTO "mailboxer_receipts" ("created_at", "mailbox_type", "notification_id", "receiver_id", "receiver_type", "updated_at") VALUES (?, ?, ?, ?, ?, ?)  [["created_at", "2014-06-24 17:51:36.222349"], ["mailbox_type", "inbox"], ["notification_id", 3], ["receiver_id", 5], ["receiver_type", "User"], ["updated_at", "2014-06-24 17:51:36.222349"]]
   (2.9ms)  commit transaction
   (0.1ms)  begin transaction
  SQL (0.8ms)  INSERT INTO "mailboxer_receipts" ("created_at", "is_read", "mailbox_type", "notification_id", "receiver_id", "receiver_type", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["created_at", "2014-06-24 17:51:36.229168"], ["is_read", "t"], ["mailbox_type", "sentbox"], ["notification_id", 3], ["receiver_id", 1], ["receiver_type", "User"], ["updated_at", "2014-06-24 17:51:36.229168"]]
   (0.9ms)  commit transaction
   (0.3ms)  SELECT COUNT(*) FROM "mailboxer_conversation_opt_outs"  WHERE "mailboxer_conversation_opt_outs"."conversation_id" = ? AND "mailboxer_conversation_opt_outs"."unsubscriber_type" = 'User' AND "mailboxer_conversation_opt_outs"."unsubscriber_id" = 5  [["conversation_id", 3]]
   (0.4ms)  SELECT COUNT(*) FROM "mailboxer_notifications"  WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = ?  [["conversation_id", 3]]



 => #<Mailboxer::Receipt id: 6, receiver_id: 1, receiver_type: "User", notification_id: 3, is_read: true, trashed: false, deleted: false, mailbox_type: "sentbox", created_at: "2014-06-24 17:51:36", updated_at: "2014-06-24 17:51:36"> 

I was having the same problem and I talk to the guy that did the sample app and did the update to 4.1. 我遇到了同样的问题,我和做示例应用程序并将其更新到4.1的那个人交谈。 You can use that to guide you. 您可以用它来指导您。

I use it like this: 我这样使用它:

Controller 控制者

def index
        @inbox ||= current_user.mailbox.inbox
end 

View 视图

<% @inbox.each do |conversation| %>
    <%= conversation.originator.username%>
    <%= link_to  raw(truncate(strip_tags(conversation.subject), :length => 15)), conversation_path(conversation) %> 
        <%= link_to "", {:controller => "conversations", :action => "trash", :id => conversation.id}, :title=> "Move to Trash", :method=>'post', data: { confirm: '¿Estas seguro?' }, :class=> "btn btn btn-danger icon-remove" %>
     <%= conversation.updated_at%>
<% end %>

thats a idea so you can get started. 多数民众赞成在一个想法,所以你可以开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM