0

メールボックスの宝石を試してみると、ビューでメッセージショーで送信者のアバターを参照でき、それは完璧に機能しますが、受信トレイの会話ビューで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 に答える