Hello,
I would appreciate help figuring out how to display any validation
errors from Paperclip when a user tries to upload an invalid file.
The problem is that the attribute SimpleForm uses for the file field
does not match any of the actual columns/attributes managed by
Paperclip.
For example, here is my model:
class Document < ActiveRecord::Base
has_attached_file :attachment,
validates_attachment_presence :attachment
validates_attachment_size :attachment, :less_than =>
10.megabytes
end
And here is my form:
= simple_form_for @document, :html => {:multipart => true} do |f|
= f.error_notification
= f.input :title
= f.input :attachment, :as => :file, :required => true
= f.submit
I would like SimpleForm to display on the :attachment field any/all
errors that Paperclip generates. So if the user doesn't upload any
file, or uploads one which is too large, SimpleForm will render the
message(s) in the :attachment field's error span.
The Paperclip errors in this case are keyed on `attachment_file_name`
(to validate the presence) and `attachment_file_size`.
Is there a way to pass a regexp to SimpleForm's input method to tell
it which attributes' errors to gather up? E.g.:
= f.input :attachment, :as => :file, :required => true, :errors_on
=> /attachment/
That would be super helpful!
Many thanks,
Andy Stewart
----
http://airbladesoftware.com