Created
December 7, 2012 17:15
-
-
Save mateusg/4234792 to your computer and use it in GitHub Desktop.
Paperclip input for Simple Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaperclipFileInput < SimpleForm::Inputs::FileInput | |
def input | |
value = object.persisted? && object.reload.send(attribute_name) | |
current_image_tag = if value.present? && value.content_type =~ /image/ | |
template.image_tag(value.url, :alt => "#{attribute_name}_image") | |
else | |
"" | |
end | |
current_image_tag + super | |
end | |
def errors_on_attribute | |
object.errors[attribute_name] + | |
object.errors["#{attribute_name}_file_name"] + | |
object.errors["#{attribute_name}_content_type"] + | |
object.errors["#{attribute_name}_file_size"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment