nested attributes paperclip
开发者_开发百科Use paperclip for my images.
Models:
class Country < ActiveRecord::Base
has_many :regions
has_many :assets, :dependent => :destroy
accepts_nested_attributes_for :assets
end
class Asset < ActiveRecord::Base
belongs_to :country
has_attached_file :image,
:styles => {
:thumb=> "100x100>",
:small => "300x300>",
:large => "600x600>"
}
end
My country index.html looks like this:
countries.each do |country|
country.name
I tried this:
link_to( image_tag(country.asset.image.url(:thumb)), country.asset.image.url(:original) )
But I get an error.
Someone ideas, what i am doing wrong?
You have got MANY assets for each country
countries.each do |country|
country.name
country.assets.each do |asset|
link_to( image_tag(asset.image.url(:thumb)), asset.image.url(:original) )
Or change it to has_one
association
精彩评论