Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to display associated model's fields
    primarykey
    data
    text
    <p>Hey all, I'm having a pretty weird problem and am having trouble isolating the cause. I get the feeling its a simple solution, but I was hoping for a nudge in the right direction. I have the following models:</p> <pre><code>class User &lt; ActiveRecord::Base has_many :pnotes class Pnote &lt; ActiveRecord::Base belongs_to :preport belongs_to :user class Preport &lt; ActiveRecord::Base has_many :pnotes, :dependent=&gt;:destroy </code></pre> <p>The Pnote portion of my schema looks as so:</p> <pre><code>create_table "pnotes", :force =&gt; true do |t| t.integer "preport_id" t.integer "user_id" t.text "content" t.datetime "created_at" t.datetime "updated_at" end </code></pre> <p>I'm trying to display all of the Pnotes associate with a given Preport on the show page of the Preport</p> <p>My Preport Controller has the following code for the show action: </p> <pre><code>def show @board = Board.find(params[:board_id]) @preport = @board.preport @pnotes = @preport.pnotes @pnote=@preport.pnotes.build respond_to do |format| format.html # show.html.erb format.xml { render :xml =&gt; @preport } end end </code></pre> <p>So now in my show.html.erb in the Preports folder, I am trying to display a list of the Pnotes as such:</p> <pre><code>&lt;ul&gt; &lt;% @pnotes.each do |pnote| %&gt; &lt;li&gt;&lt;%= pnote.user.login %&gt;&lt;span&gt;-&lt;%=pnote.content %&gt;&lt;/span&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; </code></pre> <p>"login" is the standard field that came along with the Devise Authentication Gem.</p> <p>However, this gives me the following error:</p> <blockquote> <p>undefined method `login' for nil:NilClass</p> </blockquote> <p>If I change the view to this: <li>&lt;%= pnote.user%>-&lt;%=pnote.content %></li></p> <p>I get : </p> <pre><code>#&lt;User:0x106c25888&gt;-Testing </code></pre> <p>, so it appears that it is identifying the associated user, but unable to grab its attributes.</p> <p>Any advice would be greatly appreciated! I feel like there is a fairly small oversight going on here, but I am unable to distinguish from exactly where</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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