Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Created August 8, 2009 16:56
Show Gist options
  • Save mrrooijen/164456 to your computer and use it in GitHub Desktop.
Save mrrooijen/164456 to your computer and use it in GitHub Desktop.
# Inside the model.rb
has_attached_file :image,
:url => "/assets/images/:style/:id.:basename.:extension",
:path => ":rails_root/public/assets/images/:style/:id.:basename.:extension",
:styles => {
:small => '50x45#',
:medium => '150x150',
:large => '300x300'
}
# Validations
validates_attachment_presence :image, :message => "You are required to select an image."
validates_attachment_size :image, :less_than => 2.megabytes, :message => "must be less than 500 kilobytes."
validates_attachment_content_type :image, :content_type => ['image/jpg', 'image/jpeg','image/gif','image/png','image/pjpeg','image/x-png'], :message => "Must be JPG PNG or GIF."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment