Note that there are some explanatory texts on larger screens.

plurals
  1. POnested_messages not showing previous messages
    primarykey
    data
    text
    <p>I have been followingg the rails cast 262 for the ancestry gem so I can use nested messaging. The issue I have is when I view a message it does not list the other messages from the tree. Message id 26 <code>ancestry</code> is 7 (7 is the message that was responded to). Message id 27 <code>ancestry</code> is 7, 26. When I view the original message id 7, it duplicates the content three separate times. If I view message id 26 it duplicates it's content two times. If I view message id 27 it shows no duplication.</p> <p>How it is supposed to work is when I view any of these message ids, it should list the content from the <code>ancestry</code>.</p> <p>I am not sure what I am doing wrong.</p> <p>show.html.rb:</p> <pre><code>&lt;p&gt; &lt;strong&gt;From:&lt;/strong&gt; &lt;%= @message.sender %&gt; &lt;/p&gt; &lt;p&gt; &lt;strong&gt;To:&lt;/strong&gt; &lt;%= @message.recipient %&gt; &lt;/p&gt;&lt;div class="message"&gt; &lt;div class="created_at"&gt;&lt;%= @message.created_at.strftime('%B %-d, %Y %l:%M%P') %&gt;&lt;/div&gt; &lt;div class="content"&gt;&lt;P&gt; &lt;%= nested_messages @message.subtree.arrange(:order =&gt; :created_at) %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;% if @message.recipient == @user %&gt; &lt;%= link_to "Reply", new_user_message_path(@user, :parent_id =&gt; @message) %&gt;&lt;% end %&gt; | &lt;%= link_to "Delete", [current_user, @message], :confirm =&gt; 'Are you sure you want to delete this message?', :method =&gt; :delete %&gt; &lt;/div&gt; &lt;/div&gt; &lt;%= render "form" %&gt; &lt;p&gt; &lt;% if @message.next %&gt; &lt;%= link_to 'Next', user_message_path(current_user, @message.next) %&gt; &lt;% end %&gt; &lt;% if @message.previous %&gt; &lt;%= link_to 'Previous', user_message_path(current_user, @message.previous) %&gt; &lt;% end %&gt; &lt;/p&gt; &lt;p&gt; &lt;% if @message.recipient == @user %&gt; &lt;%= link_to "Reply", new_user_message_path(@user, :reply_to =&gt; @message.sender.id) %&gt; | &lt;% end %&gt; &lt;%= link_to "Inbox", user_messages_path(current_user, :mailbox=&gt;:inbox)%&gt; | &lt;%= link_to "Delete", [current_user, @message], :confirm =&gt; 'Are you sure you want to delete this message?', :method =&gt; :delete %&gt; &lt;/p&gt; </code></pre> <p>messages_helper.rb:</p> <pre><code>module MessagesHelper def nested_messages(messages) messages.map do |message, sub_messages| render(message) + content_tag(:div, nested_messages(sub_messages), :class =&gt; "nested_messages") end.join.html_safe end end </code></pre> <p>_message.html.erb:</p> <pre><code>&lt;div class="message"&gt; &lt;div class="created_at"&gt;&lt;%= message.created_at.strftime("%B %d, %Y") %&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;%=h @message.body %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Inspection log:</p> <pre><code>{#&lt;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&gt;=&gt;{#&lt;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"&gt;=&gt;{#&lt;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"&gt;=&gt;{}}}} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload