Problem with getting foreign key

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 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,
Gustav

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs