# Submit\_to\_remote with image

**URL:** <https://www.ruby-forum.com/t/submit-to-remote-with-image/171817>\
**Category:** Rails\
**Created:** [July 9, 2009, 5:45pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817 "2009-07-09T17:45:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 5:45pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/1 "2009-07-09T17:45:17Z")

</div>

Anyone have an idea how I can shoehorn (or workaround) a  
submit\_to\_remote to accept html options so that I might put an image  
to it?

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/2 "2009-07-09T18:20:56Z")

</div>

Hi Janna,

On Thu, 2009-07-09 at 08:44 -0700, JannaB wrote:

> Anyone have an idea how I can shoehorn (or workaround) a  
> submit\_to\_remote to accept html options so that I might put an image  
> to it?

link\_to\_remote takes an image\_tag in place of the name text and  
the :submit option.

image\_submit\_tag will give you a straight HTTP submit with an image  
instead of a button.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/3 "2009-07-09T18:45:46Z")

</div>

Janna,

image\_submit\_tag has a nasty effect of not applying rollover but I got  
it to work by calling javascript directly:

\<%= image\_submit\_tag(’/images/your\_main\_image.jpg’,  
:title =\> “Search”,  
:class =\> “btnsearch”,  
:onmouseover =\>  
“this.src=’/images/your\_rollover\_image.jpg’”,  
:onmouseout =\> “this.src=’/images/your\_main\_image.jpg’”) %\>

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 9:05pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/4 "2009-07-09T21:05:49Z")

</div>

On Jul 9, 4:44 pm, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anyone have an idea how I can shoehorn (or workaround) a  
> submit\_to\_remote to accept html options so that I might put an image  
> to it?

if you do submit\_to\_remote blah, blah, :html =\> {…}

then that options hash is passed to button\_to\_remote (and thus  
button\_to\_function etc.)

Fred

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 8:16pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/5 "2009-07-09T20:16:10Z")

</div>

Ok, but I cannot have a submit\_to\_remote with an image, right?

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/6 "2009-07-09T21:57:51Z")

</div>

Fred,

I thnk you may be wrong on this (for once!) -or-, more likely, I cant  
find the right hash key for the image (I’m unable to discern the  
correct syntax).  
For example, the following works, but, my problem is that it doesn’t  
pick up the values of other controls on the form:

\<%= link\_to\_remote image\_tag("/images/icecube.gif"), {:url =\>{:action  
=\> ‘freezer’}} %\>

when I follow what (I think) you have suggested:

\<%= submit\_to\_remote ‘Freezer’, ‘freezer’, {:url =\> { :action =\>  
‘freezer’ }, :name =\> image\_tag("/images/icecube.gif")} %\>

doesn;t pick up the image. But The hash key may be something other  
than ‘name’ (I have tried, ‘image,’ and ‘img’ but I dont see how this  
would map to the name parameter in link\_to\_remote) -Janna B

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 10, 2009, 5:39am UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/7 "2009-07-10T05:39:20Z")

</div>

Hello–

On Jul 9, 2009, at 8:44 AM, JannaB wrote:

> Anyone have an idea how I can shoehorn (or workaround) a  
> submit\_to\_remote to accept html options so that I might put an image  
> to it?

It looks, from some of your recent posts, that the Javascript helpers  
may be more of an impediment than a help to you. The JS helpers work  
great for the things they were designed to do. Many people prefer  
simply to use Prototype or jQuery without any Rails magic. It’s not  
much harder and you your own code almost always bends to your will.

Just a thought.

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 9, 2009, 10:28pm UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/8 "2009-07-09T22:28:49Z")

</div>

On Jul 9, 8:57 pm, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> when I follow what (I think) you have suggested:
> 
> \<%= submit\_to\_remote ‘Freezer’, ‘freezer’, {:url =\> { :action =\>  
> ‘freezer’ }, :name =\> image\_tag(“/images/icecube.gif”)} %\>

That wasn’t what I was getting at.  
if you do submit\_to\_remote ‘Freezer’, ‘freezer’, :url =\> { :action =\>  
‘freezer’ }, :html =\> {…}  
then that will set html options on the input element that is  
generated.

Fred

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 11, 2009, 10:10am UTC](https://www.ruby-forum.com/t/submit-to-remote-with-image/171817/9 "2009-07-11T10:10:40Z")

</div>

I wanted to something similar and ended up monkey-patching  
JavaScriptHelper …  
[http://groups.google.ca/group/rubyonrails-talk/browse\_thread/thread/244e24285d3d883d](http://groups.google.ca/group/rubyonrails-talk/browse_thread/thread/244e24285d3d883d)
