Displaying an image in a Rails form_for

Hi,

I’ve got a public\images\DownArrow.jpg
and app\views\expenses\new.html.erb that want to present this image in
the following context:

<%= f.label :vendor %>
<%= f.text_field :vendor %> <%= f.image "DownArrow.jpg" %>
<%= select_tag "test", options_for_select(@current_vendors.collect { |v| v.nickname }), {:multiple => true} %>

But Rails gushes the unforgiving response:
undefined method `image’ for #<ActionView::Helpers::FormBuilder:
0x48194e0>

I couldn’t find anything helpful in:
ActionView::Helpers::FormHelper
http://api.rubyonrails.org/http://api.rubyonrails.org/
– Google

Any ideas?

Thanks in Advance,
Richard

On 20 March 2010 18:29, RichardOnRails
[email protected] wrote:

Hi,

I’ve got a public\images\DownArrow.jpg
and app\views\expenses\new.html.erb that want to present this image in
the following context:

<%= f.label :vendor %>
<%= f.text_field :vendor %> <%= f.image "DownArrow.jpg" %>

I think that should be
<%= image_tag “DownArrow.jpg” %>

Colin

Can you not use an <%= image_tag(“DownArrow.jpg”) %> ?

On Mar 20, 2:29 pm, RichardOnRails

Hi Colin,

I think that should be
<%= image_tag “DownArrow.jpg” %>

I tried that once merely changing f.image to f.image_tag, which I had
tried earlier.
Happily, then I noticed that you also omitted the “f.”. So you were
spot-on! Great job!

I superficially thought that all the things in the block had to be
f.xxx or generated html would be out of order, or something. Now I
realize the html is generated in the order its created, regardless of
what method is invoked to create it. At least, that’s how I’m
thinking about it now.

BTW, the rest of that code in that section is:

<%= f.label :vendor %>
<%= f.text_field :vendor %> <%= image_tag "DownArrow.jpg" %>
<%= select_tag "test", options_for_select(@current_vendors.collect { |v| v.nickname }), {:multiple => true} %>

So I no longer need the sidebar I could never get working. The
select_tag was what I really wanted, but I didn’t go about seeking
properly for a week. Whew, I’m glad that’s behind me.

Best wishes,
Richard

Hi Joshua,

Thanks for your response.

Can you not use an <%= image_tag(“DownArrow.jpg”) %>

Yes. That’s essentially what I wound up with:
<%= image_tag “DownArrow.jpg” %>

My problem was that I had tried <%= f.image_tag “DownArrow.jpg” %> and
then
<%= f.image “DownArrow.jpg” %>. Colin pointed out the plain image_tag
without the “f.”
is what I needed.

Best wishes,
Richard