# Button\_to with image?

**URL:** <https://www.ruby-forum.com/t/button-to-with-image/87180>\
**Category:** Rails\
**Created:** [March 26, 2006, 12:09am UTC](https://www.ruby-forum.com/t/button-to-with-image/87180 "2006-03-26T00:09:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [March 26, 2006, 12:09am UTC](https://www.ruby-forum.com/t/button-to-with-image/87180/1 "2006-03-26T00:09:03Z")

</div>

I’m trying to use button\_to and have it use an image in place of the  
submit button. I had figured it would work the same as link\_to like so:

button\_to(image\_tag(“editicon”, :size =\> “16x16”, :border =\> 0), :action  
=\> ‘edit’, :id =\> person.id)

but this instead displays the image code as the button name. Surely  
there is a simple way to do this?

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [March 26, 2006, 11:53am UTC](https://www.ruby-forum.com/t/button-to-with-image/87180/2 "2006-03-26T11:53:12Z")

</div>

Ryan W. wrote:

> I’m trying to use button\_to and have it use an image in place of the  
> submit button. I had figured it would work the same as link\_to like so:
> 
> button\_to(image\_tag(“editicon”, :size =\> “16x16”, :border =\> 0), :action  
> =\> ‘edit’, :id =\> person.id)
> 
> but this instead displays the image code as the button name. Surely  
> there is a simple way to do this?

I presume that you’re talking about submiting a form, so you should use  
image\_submit\_tag instead of button\_to…

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [March 26, 2006, 1:27pm UTC](https://www.ruby-forum.com/t/button-to-with-image/87180/3 "2006-03-26T13:27:41Z")

</div>

> I presume that you’re talking about submiting a form, so you should use  
> image\_submit\_tag instead of button\_to…

button\_to itself creates a form. I’m trying to simply have an icon that  
the user clicks on to delete an entry. And I would like the protection  
of using POST instead of GET, which is why I don’t want to just use  
link\_to. Is the only way to do this to manually create the form each  
time and use image\_submit\_tag?

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [March 26, 2006, 2:26pm UTC](https://www.ruby-forum.com/t/button-to-with-image/87180/4 "2006-03-26T14:26:23Z")

</div>

Sorry, I didn’t had such needs so I don’t say how to do (is there  
something RoR can’t do ?)

But in my point of view, you should certainly not rely on the request  
method to protect from anything (as it doesn’t NOT protect you).

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [March 26, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/button-to-with-image/87180/5 "2006-03-26T15:01:10Z")

</div>

> But in my point of view, you should certainly not rely on the request  
> method to protect from anything (as it doesn’t NOT protect you).

Well, “protect” is a relative term. Suggested reading:

[http://blog.moertel.com/articles/2005/05/08/taking-the-unsafe-gets-out-of-rails](http://blog.moertel.com/articles/2005/05/08/taking-the-unsafe-gets-out-of-rails)

Often, using POST instead of GET is _far_ safer… at least from the  
standpoint of triggering destructive actions accidentally.

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [March 26, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/button-to-with-image/87180/6 "2006-03-26T17:30:52Z")

</div>

Ryan W. wrote:

> > But in my point of view, you should certainly not rely on the request  
> > method to protect from anything (as it doesn’t NOT protect you).
> 
> Well, “protect” is a relative term. Suggested reading:
> 
> [http://blog.moertel.com/articles/2005/05/08/taking-the-unsafe-gets-out-of-rails](http://blog.moertel.com/articles/2005/05/08/taking-the-unsafe-gets-out-of-rails)
> 
> Often, using POST instead of GET is _far_ safer… at least from the  
> standpoint of triggering destructive actions accidentally.

A GET request which is a _safe_ request should never alter the state of  
the application in regard to the potential risk of web crawling.

More to : [HTTP - Wikipedia](http://en.wikipedia.org/wiki/HTTP)
