0

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 %>
Cornelius Wilson
  • 2,844
  • 4
  • 21
  • 41

1 Answers1

1

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.

Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
  • I did that previously. I added the `<%= content_tag_for(:li, conversation.receipts_for(current_user)) do |receipt| %>` with setting the message variable and that was giving me ``undefined method `image_url' for nil:NilClass`` – Cornelius Wilson Feb 28 '14 at 16:02
  • The error that you received was because `message`variable was undefined. What are you asking now, I am not quite getting? Did you set the variable and now you are getting another error? – Kirti Thorat Feb 28 '14 at 16:21
  • After setting the variable the error is now ``undefined method `image_url' for nil:NilClass`` – Cornelius Wilson Feb 28 '14 at 16:33
  • 1
    Check if for that particular sender `avatar` file is uploaded or not. This error would come only when avatar is not present for the sender. – Kirti Thorat Feb 28 '14 at 16:35
  • Rather than commenting here, see if you could come on chat http://chat.stackoverflow.com/rooms/48530/ror we can debug better – Kirti Thorat Feb 28 '14 at 16:36
  • You were right. I had one account that did not have avatar assigned. Totally overlook that. Thank you for the help! – Cornelius Wilson Feb 28 '14 at 16:37
  • Hope you accept the answer for the original question and if possible up vote too. :) – Kirti Thorat Feb 28 '14 at 16:38