What is the difference between f.template.image_tag and image_tag?

268 views Asked by At

When you want to show a photo in your forms, consensus says to do something like this:

ActiveAdmin.register Foobar do
  form :html => {:multipart => true} do |f|                                      
    f.input :thumbnail, :required => false, :as => :file,                      
            :hint => f.template.image_tag( f.object.thumbnail.url(:thumb) )       
    end                                                                          
    f.actions                                                                    
  end
end

When I did that I got this:

#<#<Class:0x00000004950908>:0x0000000494d960>
<li class="file input optional" id="property_thumbnail_input"><label class="label" for="property_thumbnail">Thumbnail</label><input id="property_thumbnail" name="property[thumbnail]" type="file">

<p class="inline-hints"><img alt="431270" src="/system/properties/thumbnails/000/000/015/thumb/431270.png?1416340571"></p></li>

So yeah, I got hex codes rendered in my page :/

And it goes away if I simply:

:hint => image_tag( f.object.thumbnail.url(:thumb) )

software versions:

formtastic (3.0.0)

paperclip (4.2.0)

1

There are 1 answers

0
Timo Schilling On

f.template.image_tag and image_tag are the same, but the result of methods called on f.template are going a different way then the result of a image_tag call. This behaves on internals of ActiveAdmin, the reason is that ActiveAdmin support Arbre in the form since a while.