Skip to content

Instantly share code, notes, and snippets.

@aiaio
Created June 11, 2009 21:09
Show Gist options
  • Save aiaio/128238 to your computer and use it in GitHub Desktop.
Save aiaio/128238 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
has_many :images, :class_name => "ProductImage"
end
class ProductImage < ActiveRecord::Base
belongs_to :product
has_attached_file :image,
:storage => :filesystem,
:path => ":rails_root/public/images/products/:attachment/:id/:style/:basename.:extension",
:url => "/images/products/:attachment/:id/:style/:basename.:extension",
# Because the :styles key can take a Proc object as an argument, we can specify the image
# styles dynamically based on the image's label.
:styles => Proc.new {|this|
defionition = ProductImageDefinitions.detect {|spec| spec[:label] == this.instance.label}
definition[:styles].merge(:thumb => '200x200>')
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment