I’ve just made a fork of attachment_fu plugin: http://github.com/artemv/attachment_fu/tree/master.

This fork provides validation errors customization means.
Now you can pass custom error formatter method names to validates_as_attachment:


validates_as_attachment :error_formatters => {:content_type => :add_content_type_error, :size => :add_size_error}

Here’s an example of error formatter. It uses Globalize to translate the message template:

    def add_content_type_error(options)
      return if !filename #content type doesn't matter if there's no file
      msg = sprintf(("Your file's format (%s) is denied. Allowed are only " +
          "image formats.").translate, options[:value])

      #don't try to translate string expanded with parameters
      msg.translated = true

      #for it to not mix with attribute name (and break .translated state)
      errors.add_to_base(msg)
    end

Also it applies fixes against ‘Size is not included in the list error’ issue
(which is often reproduced on Windows) suggested at
http://railsforum.com/viewtopic.php?pid=26427#p26427.

Short attachment_fu tutorial: http://clarkware.com/cgi/blosxom/2007/02/24#FileUploadFu



No Responses Yet to “attachment_fu fork with validation messages customization”  

  1. No Comments Yet

Leave a Reply