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! -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
1) :sort is not an option user :order. 2) Models should be accessed from the controller only 3) Post the error message -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---