首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mailboxer Gem Rails 4-创建视图

Mailboxer Gem Rails 4-创建视图
EN

Stack Overflow用户
提问于 2014-06-25 12:18:13
回答 1查看 402关注 0票数 0

我很难在Rails 4中实现Mailboxer gem的视图。到目前为止,我已经设置了它,用户可以向其他用户发送消息,但我没有任何方法让用户查看他们的对话。

即使在我创建了部分视图之后,我也得到了这个错误:(试图从示例应用程序复制视图)

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

所以我最终只是删除了视图。下面是我发送消息时发生的情况:

代码语言:javascript
复制
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"> 
EN

回答 1

Stack Overflow用户

发布于 2014-07-14 17:35:54

我也遇到了同样的问题,我和开发sample应用程序并更新到4.1版本的人聊了聊。你可以用它来指导你。

我是这样使用它的:

控制器

代码语言:javascript
复制
def index
        @inbox ||= current_user.mailbox.inbox
end 

视图

代码语言:javascript
复制
<% @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 %>

这是一个想法,这样你就可以开始了。

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

https://stackoverflow.com/questions/24400109

复制
相关文章

相似问题

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