Skip to content

Instantly share code, notes, and snippets.

@wooly
Created June 6, 2013 15:00
Show Gist options
  • Save wooly/5722156 to your computer and use it in GitHub Desktop.
Save wooly/5722156 to your computer and use it in GitHub Desktop.
Nicer Image uploads for simple_form with jasny bootstrap
# app/inputs/nice_image_input.rb
class NiceImageInput < SimpleForm::Inputs::Base
def input
template.content_tag(:div, class: "fileupload fileupload-new", data: { provides: "fileupload" }) do
template.concat(template.content_tag(:div, class: "fileupload-new thumbnail", style: "width: 100px; height: 100px; margin-right: 4px;") do
template.image_tag(object.image.url(:thumb), class: "input-prepend", size:"100x100")
end)
template.concat(template.content_tag(:div, nil, class: "fileupload-preview fileupload-exists thumbnail", style: "width: 100px; height: 100px; margin-right: 4px;"))
template.concat(template.content_tag(:span, class:"btn btn-file") do
template.concat(template.content_tag(:span, "Select image", class: "fileupload-new"))
template.concat(template.content_tag(:span, "Select image", class: "fileupload-exists"))
template.concat(@builder.file_field attribute_name, input_html_options)
end)
end
end
end
# Use with f.input :image, :as => :nice_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment