尝试使用邮箱gem并在视图中我可以在消息节目中引用发送者头像并且它工作正常,但在收件箱的对话视图中,我收到一个undefined local variable or method `message'
具有相同的代码。我对代码进行了几次调整,但我似乎无法提出显示发件人头像的正确行。
对话收件箱视图:
<%= 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 %>
消息视图:
<%= 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 %>
答案 0 :(得分:1)
在“对话收件箱”视图中设置message
变量的值,就像您在“消息”视图中所做的那样
<% message = receipt.message %> ## In Message View
在对话视图中未定义 message
变量,这是导致错误的原因。