Nested relations image url in paperclip

xvidun

I have two rails models with the relationship user has many designs. designs has an 'has_attached_file' of paperclip.

So when I do the following for an image tag it works fine.

@img_des = current_user.designs.first.img.url

But can't get this to work.

@img_des = current_user.designs.where(id: params[:id]).img.url

Throws the following error

NoMethodError in DesignerController#show undefined method `design' for #<ActiveRecord::Relation::ActiveRecord_Relation_Design:0xb1ede48>

Any suggestions, mostly it must be due to my lack of understanding of rails nested models.

hawk

For single record it's better to use find

@img_des = current_user.designs.find(params[:id]).img.url

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related