Created
March 26, 2011 14:37
-
-
Save andrellima/888330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Gallery < ActiveRecord::Base | |
has_many :gallery_photos | |
accepts_nested_attributes_for :gallery_photos | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GalleryPhoto < ActiveRecord::Base | |
belongs_to :gallery | |
has_attached_file :photo, | |
:styles => { :small => ["150", :png], :large => ["500", :png], :very_large => ['750x500>', :png] }, | |
:path => ":rails_root/public/images/:class/:attachment/:id/:style_:basename.png", | |
:url => "/images/:class/:attachment/:id/:style_:basename.png", | |
:default_url => "/images/sem_imagem.gif" | |
def geometry | |
geo = Paperclip::Geometry.from_file(photo.to_file(:large)) | |
ratio = geo.width/geo.height | |
if ratio > 1 | |
return 'horizontal' | |
else | |
return 'vertical' | |
end | |
end | |
def width | |
geo = Paperclip::Geometry.from_file(photo.to_file(:large)) | |
return geo.width | |
end | |
def height | |
geo = Paperclip::Geometry.from_file(photo.to_file(:large)) | |
return geo.height | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment