Sha256: e014c6089edcca13dc56b4b3c777890f70ca395cc150d90047a1efbac4aa5371
Contents?: true
Size: 951 Bytes
Versions: 5
Compression:
Stored size: 951 Bytes
Contents
module Brightcontent class Attachment < ActiveRecord::Base belongs_to :attachable, polymorphic: true, :inverse_of => :attachments has_attached_file :asset, :styles => lambda {|attachment| attachment.instance.attachment_styles } before_post_process :resize_images default_scope order("id") delegate :url, to: :asset validates :asset, attachment_presence: true def attachment_styles default_attachment_styles.merge(user_defined_styles) end def image? asset_content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$} end private def user_defined_styles if attachable && attachable.respond_to?(:attachment_styles) && image? attachable.attachment_styles end || {} end def default_attachment_styles { brightcontent: "100x100#", main: "200x200#" } end def resize_images return false unless image? end end end
Version data entries
5 entries across 5 versions & 1 rubygems