Rails 4: How to get first image(child) from an album(parent) for index page
<p>Album has many images. To display all of my albums on the index page I'd like to have a thumbnail of the first image of the album. Rather than adding an attachment to the album, I was wondering if there was a way I could just pull the first image from that particular album. </p>

<p>This is what I have currently:</p>

<p><strong>albums/index.html.erb</strong></p>

<pre><code>&lt;% @albums.each do |a| %&gt;
   &lt;div class="thumbnail"&gt;
      &lt;%= link_to image_tag(a.images.first(:thumb)), a %&gt;                     
         &lt;div class="caption"&gt;
            &lt;h3&gt;&lt;%= a.title %&gt;&lt;/h3&gt;
               &lt;p&gt;&lt;%= a.description %&gt;&lt;/p&gt;
         &lt;/div&gt;
    &lt;/div&gt;
&lt;% end %&gt;
</code></pre>

<p><strong>models/image.rb</strong></p>

<pre><code>class Image &lt; ActiveRecord::Base

 belongs_to :album

 has_attached_file :photo, 
 styles: { large: "700x700&gt;", medium: "450&gt;", thumb: "200x200&gt;" },
 storage: :s3,
 s3_credentials: Proc.new{ |a| a.instance.s3_credentials }

 validates_attachment_content_type :photo, content_type: /\Aimage\/.*\Z/

 validates_presence_of :title
 validates_presence_of :album_id

 def s3_credentials
    {
      access_key_id:     ENV["AWS_ACCESS_KEY_ID"],
      secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
      s3_region:         ENV["AWS_REGION"],
      bucket:            ENV["S3_BUCKET_NAME"]
    }
 end
end
</code></pre>

<p>I'm getting an error "can't convert Symbol into Integer" that points to the line with the <code>image_tag</code></p>