Module: Polygallery::ActsAsPolyphoto::ClassMethods
- Defined in:
- app/models/concerns/polygallery/acts_as_polyphoto.rb
Instance Method Summary collapse
- #acts_as_polyphoto(options = {}) ⇒ Object
- #init_associations(settings = HasPolygallery::DEFAULTS) ⇒ Object
- #init_attachment(paperclip_settings) ⇒ Object
- #polygallery_settings ⇒ Object
Instance Method Details
#acts_as_polyphoto(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 9 def acts_as_polyphoto(={}) defaults = self.polygallery_settings settings = defaults.deep_merge() attr_accessor :photo_to_upload, :polygallery_options, :polyphoto_initialized settings[:paperclip] init_associations settings before_validation :process_photo_to_upload # before_save { # # puts "Photo changes: #{self.changes.inspect}" # puts 'SAVING PHOTO!' } after_initialize do self. ||= self.polygallery_settings self.initialize_polyphoto end include ActsAsPolyphoto::LocalInstanceMethods end |
#init_associations(settings = HasPolygallery::DEFAULTS) ⇒ Object
47 48 49 50 51 52 |
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 47 def init_associations(settings=HasPolygallery::DEFAULTS) belongs_to settings[:association_names][:gallery], :class_name => settings[:associations][:gallery][:class_name], :foreign_key => :gallery_id belongs_to :galleryable, :polymorphic => true end |
#init_attachment(paperclip_settings) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 36 def (paperclip_settings) has_attached_file :photo, :styles => ->(a) { a.instance.paperclip_settings[:styles] }, :default_url => paperclip_settings[:default_url] validations = polygallery_settings[:paperclip_validations] (:photo, :content_type => validations[:content_type]) if validations[:content_type] (:photo) if validations[:presence] end |
#polygallery_settings ⇒ Object
32 33 34 |
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 32 def polygallery_settings HasPolygallery::DEFAULTS end |