# Button\_to or link\_to using an image?

**URL:** <https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365>\
**Category:** Rails\
**Created:** [November 27, 2006, 12:07pm UTC](https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365 "2006-11-27T12:07:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brndn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/dec6dc/32.png) [@brndn](https://www.ruby-forum.com/u/brndn)\
**Post date:** [November 27, 2006, 12:07pm UTC](https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365/1 "2006-11-27T12:07:15Z")

</div>

I’m trying to link to action using an image. This is what I’m working  
with:

![]()

\<%= button\_to (‘Details’, :action =\> ‘details’, :id =\> product ) %\>

Is there a good way to make the _image_ the clickable item? Any  
insights into button\_to, and link\_to that you want to share are  
appreciated.

---

<div class="post-metadata">

**Author:** ![brndn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/dec6dc/32.png) [@brndn](https://www.ruby-forum.com/u/brndn)\
**Post date:** [November 27, 2006, 12:57pm UTC](https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365/2 "2006-11-27T12:57:24Z")

</div>

On 27 November 2006 14:05, Brandon wrote:

> I’m trying to link to action using an image. This is what I’m working  
> with:
> 
> ![]()
> 
> \<%= button\_to (‘Details’, :action =\> ‘details’, :id =\> product ) %\>
> 
> Is there a good way to make the _image_ the clickable item? Any  
> insights into button\_to, and link\_to that you want to share are  
> appreciated.

\<%= link\_to image\_tag(product.image\_url), :action =\> ‘details’, :id =\>  
product %\>

---

<div class="post-metadata">

**Author:** ![brndn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/dec6dc/32.png) [@brndn](https://www.ruby-forum.com/u/brndn)\
**Post date:** [November 27, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365/3 "2006-11-27T21:50:42Z")

</div>

Thanks a lot!

Is that basically a nested method?

---

<div class="post-metadata">

**Author:** ![brndn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/dec6dc/32.png) [@brndn](https://www.ruby-forum.com/u/brndn)\
**Post date:** [November 27, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365/4 "2006-11-27T22:20:45Z")

</div>

On 11/27/06, Brandon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks a lot!
> 
> Is that basically a nested method?

This is the same, but more readable. You pass the image as first  
parameter  
to the link\_to method. The one posted before was simply omitting  
parenthesis:

\<%= link\_to(image\_tag(product.image\_url), :action =\> ‘details’, :id =\>  
product) %\>

---

<div class="post-metadata">

**Author:** ![brndn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/dec6dc/32.png) [@brndn](https://www.ruby-forum.com/u/brndn)\
**Post date:** [November 28, 2006, 4:21am UTC](https://www.ruby-forum.com/t/button-to-or-link-to-using-an-image/77365/5 "2006-11-28T04:21:42Z")

</div>

which is better without parenthesis because it more legible, right?
