# Problem with getting foreign key

**URL:** <https://www.ruby-forum.com/t/problem-with-getting-foreign-key/85142>\
**Category:** Rails\
**Created:** [February 10, 2007, 1:21pm UTC](https://www.ruby-forum.com/t/problem-with-getting-foreign-key/85142 "2007-02-10T13:21:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@gustav](https://www.ruby-forum.com/u/gustav)\
**Post date:** [February 10, 2007, 1:21pm UTC](https://www.ruby-forum.com/t/problem-with-getting-foreign-key/85142/1 "2007-02-10T13:21:39Z")

</div>

Hi,  
This is probably a no-brainer, but despite my best efforts I can’t seem  
to fix it… I have two tables, “products” and “pictures”. In the  
products-table I have one column named “picture\_id”, referrencing the  
picture for the product.

has\_many/belongs\_to-relationship is hooked up and in my picture-model I  
have defined:

def picture=(picture\_field)  
self.name = base\_part\_of(picture\_field.original\_filename)  
self.content\_type = picture\_field.content\_type.chomp  
self.data = picture\_field.read  
end

In my controller I have defined:

def picture  
@picture = Picture.find(params[:id])  
send\_data(@picture.data,  
:filename =\> @picture.name,  
:type =\> @picture.content\_type,  
:disposition =\> “inline”)  
end

def show\_product  
@product = Product.find(params[:id])  
end

In my show\_product-view I have defined:

![]()

Displaying picture using [http://localhost:3000/main/picture/5](http://localhost:3000/main/picture/5) works like  
a breeze, however I can’t seem to get the picture to display when  
calling it from my “show\_product.rhtml”-file. I get this error message  
when trying to load [http://localhost:3000/main/show\_product/5:](http://localhost:3000/main/show_product/5:)

undefined method `picture’ for #Product:0x2461fd0

Getting other foreign keys (ex. @product.designer) works ok, and I know  
that the key is in the table, since I can see the number in my  
admin-interface. What am I missing?

Best regards och many thanks,  
Gustav
