Question

Trying the mailboxer gem and in the views I can reference the sender avatar in the message show and it works perfect, but in the conversation view of the inbox I receive a undefined local variable or method `message' with the same code. I made several adjustments to the code but I can't seem to come up with the right line that will display the senders avatar.

Conversation Inbox View:

<%= content_tag_for(:li, conversation) do |conversation| %>
    <%= link_to conversation.subject, conversation%> - <%= conversation.updated_at.strftime("%B %-d, %Y %l:%M%P") %>
    | From: <% conversation.participants.each do |participant| %>
     <% if participant != current_user %>
      <%= link_to participant.username, participant %>  
     <% end %>
    <% end %>
    <%= image_tag message.sender.avatar.image_url(:avatar) %>
|
    <% if conversation.is_completely_trashed?(current_user)%>
      <%= link_to 'Untrash', [:untrash, conversation], method: :post%>
    <%else%>
      <%= link_to 'Move to trash', [:trash, conversation], method: :post%>

<% end %>
<% end %>

Message View:

<%= conversation.subject %>

From:
<% conversation.participants.each do |participant| %>
 <% if participant != current_user %>
  <%= link_to participant.username, participant %>
 <% end %>
<% end %>
<%= content_tag_for(:li, conversation.receipts_for(current_user)) do |receipt| %>
 <% message = receipt.message %>
 From: <%= message.sender.username %>
<%= image_tag message.sender.avatar.image_url(:avatar) %>

 <%= simple_format h message.body %>

 Sent <%= conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %>

<% end %>

<%= render 'messages/form', conversation: conversation %>
Was it helpful?

Solution

Set the value of message variable in the Conversation Inbox view like you have done in Message view

<% message = receipt.message %> ## In Message View

message variable is not defined in Conversation view that is the reason for error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top