0

尝试使用邮箱 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 %>
4

1 回答 1

1

message像在消息视图中所做的那样,在对话收件箱视图中 设置变量的值

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

message变量未在会话视图中定义,这是错误的原因。

于 2014-02-27T19:46:28.283 回答