I am trying to only fetch the first record in my table for display. I am creating a site where a user can upload multiple images and attach to a post but I only want to display the first image view for each post.
For further clarification posts belong_to projects
. So when you are on the projects show page you see multiple posts. In this view I only want to display the first image for each post. Is there a way to do this in the view without affecting the controller (as later I want to allow users to browse all photos through the addition of a lightbox). Here is my /views/posts/_post.html.erb code:
<% div_for post do %>
<% post.photos.each do | photo | %>
<%= image_tag(photo.data.url(:large), :alt => '') %>
<%= photo.description %>
<% end unless post.photos.first.new_record? rescue nil %>
<%= link_to h(post.link_title), post.link %>
<%= h(post.description) %>
<%= link_to 'Manage this post', edit_post_path(post) %>
<% end %>
UPDATE: I am using a photos model to attach multiple photos to each post and using paperclip here.