我一直在遵循軌道鑄262祖先的寶石,所以我可以使用嵌套消息。我遇到的問題是,當我查看消息時,它沒有列出樹中的其他消息。消息ID 26 ancestry
是7(7是被回覆的消息)。消息ID 27 ancestry
是7,26。當我查看原始消息ID 7時,它會在三個不同的時間複製內容。如果我查看消息ID 26,它會重複它的內容兩次。如果我查看消息ID 27,它不顯示重複。nested_messages沒有顯示以前的消息
它應該如何工作是當我查看這些消息ID時,它應該列出ancestry
中的內容。
我不知道我在做什麼錯。
show.html.rb:
<p>
<strong>From:</strong>
<%= @message.sender %>
</p>
<p>
<strong>To:</strong>
<%= @message.recipient %>
</p><div class="message">
<div class="created_at"><%= @message.created_at.strftime('%B %-d, %Y %l:%M%P') %></div>
<div class="content"><P>
<%= nested_messages @message.subtree.arrange(:order => :created_at) %>
</div>
<div class="actions">
<% if @message.recipient == @user %>
<%= link_to "Reply", new_user_message_path(@user, :parent_id => @message) %><% end %>
|
<%= link_to "Delete", [current_user, @message], :confirm => 'Are you sure you want to delete this message?', :method => :delete %>
</div>
</div>
<%= render "form" %>
<p>
<% if @message.next %>
<%= link_to 'Next', user_message_path(current_user, @message.next) %>
<% end %>
<% if @message.previous %>
<%= link_to 'Previous', user_message_path(current_user, @message.previous) %>
<% end %>
</p>
<p>
<% if @message.recipient == @user %>
<%= link_to "Reply", new_user_message_path(@user, :reply_to => @message.sender.id) %>
|
<% end %>
<%= link_to "Inbox", user_messages_path(current_user, :mailbox=>:inbox)%>
|
<%= link_to "Delete", [current_user, @message], :confirm => 'Are you sure you want to delete this message?', :method => :delete %>
</p>
messages_helper.rb:
module MessagesHelper
def nested_messages(messages)
messages.map do |message, sub_messages|
render(message) + content_tag(:div, nested_messages(sub_messages), :class => "nested_messages")
end.join.html_safe
end
end
_message.html.erb:
<div class="message">
<div class="created_at"><%= message.created_at.strftime("%B %d, %Y") %></div>
<div class="content">
<%=h @message.body %>
</div>
</div>
檢查日誌:
{#<Message id: 7, sender_id: 3, recipient_id: 1, sender_deleted: 0, recipient_deleted: 0, subject: "mountain", body: "okok", read_at: "2013-12-06 21:54:33", container: "draft", created_at: "2013-12-05 19:39:11", updated_at: "2013-12-06 21:54:33", conversation_id: nil, original_message_id: nil, ancestry: nil>=>{#<Message id: 26, sender_id: 1, recipient_id: 3, sender_deleted: 0, recipient_deleted: 0, subject: "why s it", body: "isjdkjdjkd", read_at: "2013-12-20 16:46:26", container: "draft", created_at: "2013-12-20 16:21:00", updated_at: "2013-12-20 16:46:26", conversation_id: nil, original_message_id: nil, ancestry: "7">=>{#<Message id: 27, sender_id: 3, recipient_id: 1, sender_deleted: 0, recipient_deleted: 0, subject: "not sure", body: "i'm just continuing the conversation dude!", read_at: "2013-12-20 16:48:02", container: "draft", created_at: "2013-12-20 16:46:45", updated_at: "2013-12-20 16:48:02", conversation_id: nil, original_message_id: nil, ancestry: "7/26">=>{}}}}
你可以分享你的'app/views/messages/_message.html.erb'代碼嗎?此外,如果您在show.html.erb內的某個地方添加了<%= @ message.subtree.arrange(:order =>:created_at).inspect%>,它會顯示什麼內容? – cschroed
我添加了代碼和檢查行的顯示內容。它使用.inspect顯示所有嵌套的消息。 –