lib/has-attached.rb in has-attached-0.1.9 vs lib/has-attached.rb in has-attached-0.2.2

- old
+ new

@@ -29,11 +29,11 @@ extend ActiveSupport::Concern module ClassMethods def has_attached(name, options = {}) - + options[:url] ||= "/attachments/:class/:id/:attachment/:style/:basename.:extension" options[:path] ||= ":rails_root/public/attachments/:class/:id/:attachment/:style/:basename.:extension" @all_styles ||= (YAML.load_file(Rails.root.join("config", "styles.yml")) rescue {"styles" => {}})["styles"] options[:styles] = @all_styles.fetch(self.name.underscore, {}).fetch(name.to_s, {}).symbolize_keys @@ -56,9 +56,21 @@ validate do |record| if record.send(name) && !record.send(name).errors.empty? file_name = record.send(:"#{name}_file_name") record.errors.add name, "Paperclip returned errors for file '#{file_name}' - check ImageMagick installation or image source file." false + end + end + + attr_accessor :"#{name}_delete" + + define_method :"#{name}_delete" do + false + end + + define_method :"#{name}_delete=" do |val| + if val == "1" + send(name).clear end end end