title: Realizing timeline on mypage
body: <p>1.What I want to do.<p>
  I would like to show the messages posted in the groups, which a user already joined, on his or her timeline.as This includes the messages posted by other users as long as they are the group mates of his or her. </p>
  
  <p>2.What I did.<p>
  (show.html.erb-members)</p>
  
  <pre><code>&lt;h1&gt;Mypage&lt;/h1&gt;
   &lt;div id="timeline"&gt;
    &lt;%= @timelines.each do |tl|%&gt;
     &lt;div class="message_area"&gt;
     &lt;p class= "member_name"&gt;&lt;a href="/members/&lt;%= tl.member %&gt;"&gt;
     &lt;%= tl.member.name %&gt;&lt;/a&gt;&lt;/p&gt;
     &lt;p class="message_content"&gt;&lt;%= tl.content %&gt;&lt;/p&gt;
     &lt;p class="message_create"&gt;(&lt;%= tl.created_at.strftime'%Y-%m-%d %H:%M' %&gt;)
     &lt;/p&gt;&lt;/div&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>(members.controller.erb)</p>
  
  <pre><code>def show
    if !checklogin? then return end
     @me = me?
     @member = Member.find(params[:id])
     @timelines = []
     @timelines = @member.groups.each{|group| group.group_messages}
  </code></pre>
  
  <p>(member.rb)</p>
  
  <pre><code>class Member &lt; ActiveRecord::Base
   attr_accessible :admin, :mail, :memo, :name, :pass, :user
  
   has_many :friends
   has_many :messages
   has_many :comments
   has_many :group_in_members, :dependent =&gt; :destroy
   has_many :groups, :through =&gt; :group_in_members
  end
  </code></pre>
  
  <p>(group.rb)</p>
  
  <pre><code>class Group &lt; ActiveRecord::Base
   attr_accessible :admin, :memo, :name
   has_many :group_in_members, :dependent =&gt; :destroy
   has_many :members, :through =&gt; :group_in_members
   has_many :group_messages
  end
  </code></pre>
  
  <p>(group_message.rb)</p>
  
  <pre><code>class GroupMessage &lt; ActiveRecord::Base
   attr_accessible :content, :member_id, :group_id
    belongs_to :member
    belongs_to :group
  end
  </code></pre>
  
  <p>3.Errors</p>
  
  <pre><code>NoMethodError in Members#show
  
  Showing /Users/******/******/****/app/views/members/show.html.erb    where line #32 raised:
  
  undefined method `member' for #&lt;Group:0x007fac639e2c00&gt;
  Extracted source (around line #32):
  
  29: &lt;div id="timeline"&gt; 
  30:  &lt;%= @timelines.each do |tl|%&gt;
  31:   &lt;div class="message_area"&gt;
  32:   &lt;p class= "member_name"&gt;&lt;a href="/members/&lt;%= tl.member %&gt;"&gt;
  33:    &lt;%= tl.member.name %&gt;&lt;/a&gt;&lt;/p&gt;
  34:   &lt;p class="message_content"&gt;&lt;%= tl.content %&gt;&lt;/p&gt;
  35:   &lt;p class="message_create"&gt;(&lt;%= tl.created_at.strftime'%Y-%m-%d %H:%M' %&gt;)
  </code></pre>