简体   繁体   中英

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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