Image file input with Formtastic and ActiveAdmin

Sebastien picture Sebastien · Aug 16, 2011 · Viewed 12.9k times · Source

I started to use formstatic but I need to make a file field with image preview. I mean, when i edit an object, i want to see the image already linked.

How can I do that?

Thank you !

Answer

Sebastien picture Sebastien · Aug 18, 2011

The answer is to use the hint attribute :

ActiveAdmin.register Event do
  form :html => { :enctype => "multipart/form-data" } do |f|
    f.input :map, :as => :file, :hint => f.template.image_tag(f.object.map.url(:thumb))
  end
end

Bye