title: Rails - nested display of two related resources
body: <p>I have an events model that has many posts, and I'm trying to display the relevant the events and posts in an outline format, like so:</p>
  
  <pre><code>Event 1
    Post 1
    Post 2
  Event 2
    Post 3
    Post 4
  ...
  </code></pre>
  
  <p>I have the following currently, and for some reason, the controller can't find the "postlist" method (acting on the @eventlist instance) in my Events model.</p>
  
  <pre><code>class Event &lt; ActiveRecord::Base
    belongs_to :group
    has_many :posts
  
    def postlist
      Post.from_event_posts(self)
    end
  
  end
  
  
  class Post &lt; ActiveRecord::Base
    belongs_to :event
    belongs_to :user
  
    def self.from_event_posts(event)
      where(event_id: event.id)
    end
  
  end
  
  
  class GroupsController &lt; ApplicationController
    def show
      @eventlist = @group.eventlist #returns hash of events for a group - confirmed working
  
      #Get list of posts for each event
      @postlist = @eventlist.postlist
    end
  end
  
  
  
  &lt;%= @eventlist.each do |e| %&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;%= e.title %&gt;&lt;/li&gt;
    &lt;%= e.postlist.each do |p| %&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;%= p.comment %&gt; | &lt;%=p.user_id%&gt; &lt;/li&gt;
    &lt;/ul&gt;
    &lt;%end%&gt;
  &lt;/ul&gt;
  &lt;%end%&gt;
  </code></pre>
  
  <p>I get the following error:  undefined method `postlist' for #</p>