app/models/concerns/polygallery/acts_as_polyphoto.rb in polygallery-0.3.1 vs app/models/concerns/polygallery/acts_as_polyphoto.rb in polygallery-0.3.2
- old
+ new
@@ -8,15 +8,21 @@
module ClassMethods
def acts_as_polyphoto(options={})
defaults = self.polygallery_settings
settings = defaults.deep_merge(options)
- attr_accessor :photo_to_upload, :polygallery_options
+ attr_accessor :photo_to_upload, :polygallery_options,
+ :polyphoto_initialized
init_attachment 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.polygallery_options ||= self.polygallery_settings
self.initialize_polyphoto
end
@@ -34,16 +40,10 @@
:default_url => paperclip_settings[:default_url]
validations = polygallery_settings[:paperclip_validations]
validates_attachment_content_type(:photo, :content_type =>
validations[:content_type]) if validations[:content_type]
validates_attachment_presence(:photo) if validations[:presence]
-
- before_validation :process_photo_to_upload
- # TODO: figure out why save gets called so much!
- # before_save {
- # # puts "Photo changes: #{self.changes.inspect}"
- # puts 'SAVING PHOTO!' }
end
def init_associations(settings=HasPolygallery::DEFAULTS)
belongs_to settings[:association_names][:gallery],
:class_name => settings[:associations][:gallery][:class_name],
@@ -58,11 +58,13 @@
self.polygallery_options = settings
self.initialize_polyphoto
end
def initialize_polyphoto
+ return if self.polyphoto_initialized.present?
self.class.init_associations(self.polygallery_settings)
self.init_attachment
+ self.polyphoto_initialized = true
end
def polygallery_settings
return self.polygallery_options if self.polygallery_options.present?
if self.gallery_title.present?