Skip to content

Instantly share code, notes, and snippets.

@janlimpens
Created October 24, 2014 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janlimpens/478a3e9059032eae454b to your computer and use it in GitHub Desktop.
Save janlimpens/478a3e9059032eae454b to your computer and use it in GitHub Desktop.
class Image
include Mongoid::Document
include Mongoid::Paperclip
include Mongoid::Slug
include ComparableByIndex
include CanBePublished
embedded_in :portfolio_item, inverse_of: :images
field :title, type: String
slug :title, history: true
field :description, type: String
field :technique
field :date, type: Date
has_mongoid_attached_file :image,
path: ':img_path.:extension',
url: ':img_url.:extension',
styles: {large: '780>', medium: '320>', small: '160x160#', mini: '80x80#'},
use_timestamp: false
validates_attachment :image, content_type: { content_type: %w(image/jpg image/jpeg image/png image/gif)}
attr_accessor :delete_image
before_validation { image.clear if delete_image == '1' }
validates_presence_of :title
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment