# Am I Putting my Helper in the Wrong Place?

**URL:** <https://www.ruby-forum.com/t/am-i-putting-my-helper-in-the-wrong-place/126902>\
**Category:** Rails\
**Created:** [January 23, 2008, 11:15am UTC](https://www.ruby-forum.com/t/am-i-putting-my-helper-in-the-wrong-place/126902 "2008-01-23T11:15:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [January 23, 2008, 11:15am UTC](https://www.ruby-forum.com/t/am-i-putting-my-helper-in-the-wrong-place/126902/1 "2008-01-23T11:15:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [January 23, 2008, 11:35am UTC](https://www.ruby-forum.com/t/am-i-putting-my-helper-in-the-wrong-place/126902/2 "2008-01-23T11:35:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [January 24, 2008, 12:13am UTC](https://www.ruby-forum.com/t/am-i-putting-my-helper-in-the-wrong-place/126902/3 "2008-01-24T00:13:17Z")

</div>

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.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

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