lib/paperclip/storage/database.rb in paperclip_database-2.2.0 vs lib/paperclip/storage/database.rb in paperclip_database-2.2.1

- old
+ new

@@ -91,16 +91,11 @@ @paperclip_files = "#{instance.class.name.demodulize.underscore}_#{name.to_s}_paperclip_files" if !@paperclip_class_module.const_defined?(@paperclip_files.classify) @paperclip_file = @paperclip_class_module.const_set(@paperclip_files.classify, Class.new(::ActiveRecord::Base)) @paperclip_file.table_name = @options[:database_table] || name.to_s.pluralize @paperclip_file.validates_uniqueness_of :style, :scope => instance.class.table_name.classify.underscore + '_id' - case Rails::VERSION::STRING - when /^2/ - @paperclip_file.named_scope :file_for, lambda {|style| { :conditions => ['style = ?', style] }} - else # 3.x - @paperclip_file.scope :file_for, lambda {|style| @paperclip_file.where('style = ?', style) } - end + @paperclip_file.scope :file_for, lambda {|style| @paperclip_file.where('style = ?', style) } else @paperclip_file = @paperclip_class_module.const_get(@paperclip_files.classify) end @database_table = @paperclip_file.table_name #FIXME: This fails when using set_table_name "<myname>" in your model @@ -134,11 +129,11 @@ end end def exists?(style = default_style) if original_filename - !file_for(style).nil? + instance.send("#{@paperclip_files}").where(:style => style).exists? else false end end @@ -173,14 +168,14 @@ def flush_writes ActiveRecord::Base.logger.info("[paperclip] Writing files for #{name}") @queued_for_write.each do |style, file| case Rails::VERSION::STRING - when /^2/, /^3/ + when /^3/ paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by_style, style.to_s) when /^4/ paperclip_file = instance.send(@paperclip_files).send(:find_or_create_by, style: style.to_s) - else # 4.x + else raise "Rails version #{Rails::VERSION::STRING} is not supported (yet)" end paperclip_file.file_contents = file.read paperclip_file.save! instance.reload