Phil
On Wed, Feb 23, 2011 at 9:47 PM, John Merlino <[email protected]> wrote: > Hey all, > > with this below (a post has many blog_images and blog_image belongs to > post): > > <% @posts.each do |post| %> > > <div class="FeatureItem"> > <a href=""><img src="/images/<%= > post.blog_images.image_file_name %>" width="220" height="174" alt="" > style="top: 27px; left: 13px;" />Click Here</a> > > <div class="FeatureContent"> > <h2><a href=""><%= post.title %></a></h2> > <p><%= post.body %></p> > <p class="posted"><%= post.user_id %></p> > > </div> > </div> > <% end %> > > I get undefined method image_file_name because image_file_name is a > field in blog_images table. So activerecord generates field names as > instance methods but above I'm trying to use it as a class method, so > since there is no class method image_file_name in BlogImage class, it > throws error. Is there a way that I can get image_file_name without > creating a class mehtod because I want to pull the data dynamically from > the table, where the image file belongs to blog post. > > Thanks for response. > > You can't call image_file_name on post.blog_images, because post.blog_images returns an array, and the array doesn't have a method called image_file_name. Check something like map; eg: post.blog_images.map(&:image_file_name). > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

