Skip to content

Instantly share code, notes, and snippets.

@mateusg
Created December 7, 2012 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateusg/4234792 to your computer and use it in GitHub Desktop.
Save mateusg/4234792 to your computer and use it in GitHub Desktop.
Paperclip input for Simple Form
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