Forum: Ruby on Rails Problem with getting foreign key

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
798c7f10aed317c27155ba7c53221df6?d=identicon&s=25 Gustav (Guest)
on 2007-02-10 13:21
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) = base_part_of(picture_field.original_filename)
  self.content_type = picture_field.content_type.chomp =

In my controller I have defined:

def picture
  @picture = Picture.find(params[:id])
            :filename =>,
            :type => @picture.content_type,
            :disposition => "inline")

def show_product
  @product = Product.find(params[:id])

In my show_product-view I have defined:

<img src="<%= url_for(:action => 'picture', :id => @product.picture)

Displaying picture using 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:

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,
This topic is locked and can not be replied to.