title: Joining tables in rails 3
body: <p>Hey I'm very new to rails and would appreciate the help greatly!</p>
  
  <p>Every user has a profile page that shows all of his events. Every event has many assets (images). And every event also has its own event page. What I'm struggling with is how to display the events (if they exist) on the user profile page and do the join.</p>
  
  <p>In my profile controller i have : @events = User.joins(:events) to get the events but I then need to drill into the assets table to get the relevant image (for now I just want to grab any image that's there for that event, later i'll add a "main picture" flag).</p>
  
  <p>Here are my models.</p>
  
  <pre><code>class Asset &lt; ActiveRecord::Base
  belongs_to :event
  has_attached_file :image,
  :styles =&gt; {
    :thumb=&gt; "100x100#",
    :small  =&gt; "300x300&gt;",
    :large =&gt; "600x600&gt;"
      },
    :storage =&gt; :s3,
    :s3_credentials =&gt; "#{RAILS_ROOT}/config/s3.yml",
    :path =&gt; ":attachment/:id/:style.:extension",
    :bucket =&gt; 'wpt-assets'
  end
  
  class Event &lt; ActiveRecord::Base
  attr_accessible :name, :budget, :client, :date, :description, :venue, :attendees,  
  :assets_attributes
  belongs_to :user
  has_many :assets#, :dependent =&gt; destroy
  accepts_nested_attributes_for :assets
  end
  
  class User &lt; ActiveRecord::Base
  rolify
  devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable
  
  # Setup accessible (or protected) attributes for your model
  attr_accessible :role_ids, :as =&gt; :admin
  attr_accessible :username, :email, :password, :password_confirmation,  
  :remember_me,:avatar, :bio, :title, :company,:facebook,:twitter,:pinterest,:linkedin
  validates_presence_of :username
  validates_uniqueness_of :username, :email, :case_sensitive =&gt; false
  has_many :events
  has_attached_file :avatar, 
  :styles =&gt; { 
    :medium =&gt; "100x100&gt;", 
    :thumb =&gt; "24x24&gt;" }
  
    def to_param
      username
    end
  end
  </code></pre>