Am I Putting my Helper in the Wrong Place?

Hi,

This will probably be an easy one as I must be overlooking something
obvious. I’m trying to set up a helper method that file find the first
photo belonging to a product ( photo.sort should == 1).

def product_list_photo(id)
Photo.find(:first, :conditions => [“photo_id = ?”, id], :sort =>
“sort ASC”)
end

This helper is in products_helper.rb. It needs to be used in filecolumn
to pull up the appropriate image

<%= image_tag url_for_file_column(product_list_photo(product.id),
“title_photo”) %>

For whatever reason I keep getting an undefined variable or method
error. Am I doing something really obvious wrong?

Thanks!

  1. :sort is not an option user :order.
  2. Models should be accessed from the controller only
  3. Post the error message

Why would the table “photos” have a photo_id field in it? This is what
it
looks like when you’re doing the find.

This method should be put in the photo model… or are you trying to get
the
photo for a specific product? If you are, then it should go in the
product
model and shouldn’t actually be a method at all!

Define a has_one :photo or has_many :photos on the product model. You
will
then be able to access all related photos by doing @product =
Product.find
(:first)
@product.photos

Ryan B.

Feel free to add me to MSN and/or GTalk as this email.