# \<img onclick\> vs link\_to\_remote()

**URL:** <https://www.ruby-forum.com/t/img-onclick-vs-link-to-remote/101368>\
**Category:** Rails\
**Created:** [August 4, 2006, 3:25pm UTC](https://www.ruby-forum.com/t/img-onclick-vs-link-to-remote/101368 "2006-08-04T15:25:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 4, 2006, 3:25pm UTC](https://www.ruby-forum.com/t/img-onclick-vs-link-to-remote/101368/1 "2006-08-04T15:25:34Z")

</div>

In one of my view , I have an image the user need to click to close a

selections
 added by an Ajax call.

if I use :  
\<img src ="/images/icon\_closeitem.gif", size=“16\*16”,  
border=“0”,alt=“Close Selection”, title=“Close”, onclick="\<%=  
remote\_function(:url =\> { :controller =\> ‘property’, :action =\>  
‘closeSelection’, :id =\> @property }) %\>" \>

then it’s ok, in my property\_controller.rn  
def closeSelection  
render :update do |page|  
page.replace\_html ‘selections’, “”  
end  
end

will reset the content of the ‘selections’ div to empty… fine

but if I try to use  
\<%= link\_to\_remote (image\_tag(“icon\_edititem.gif” , :size=\>“16\*16”,  
:border=\>0, :alt=\>“Edit this Property”, :Title=\>“Edit this Property”) "  
, { :controller =\> “property”, :action =\> “delete”,:id =\> @property },  
:class =\> “additem”) %\>

the href is “#” (the onclikc seems to be generated…) the URL is  
‘property/#’ and obviously the controller action is not performed…

I surely miss an important parameter… which one ?

kad

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 4, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/img-onclick-vs-link-to-remote/101368/2 "2006-08-04T17:03:31Z")

</div>

Hi Kad,

please try:

:url =\> { :controller =\> “property”, :action =\> “delete”,:id =\>  
@property }

Cheers,  
Jan

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 4, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/img-onclick-vs-link-to-remote/101368/3 "2006-08-04T18:33:21Z")

</div>

Jan P. wrote:

> Hi Kad,
> 
> please try:
> 
> :url =\> { :controller =\> “property”, :action =\> “delete”,:id =\>  
> @property }
> 
> Cheers,  
> Jan

While this is the correct response, I must say that AJAX is way overkill  
for this. This task is just simply javascript. You are makign a  
request to the server that doesn’t change the server state in any way  
and return no useful information.

I think this would be a much better solution:

\<%= link\_to\_function image\_tag(…),  
render(:update) {|page| page.replace\_html ‘selections’, “”}  
%\>

Still uses RJS, and requires no AJAX call to the sever at all. Plus it  
will be insatnt rather than a short wait for the server to respond. Why  
query the server if you don’t need to?

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 4, 2006, 7:27pm UTC](https://www.ruby-forum.com/t/img-onclick-vs-link-to-remote/101368/4 "2006-08-04T19:27:47Z")

</div>

Hi Alex,

you’re absolutely right. I haven’t even took a closer look to what Kad  
is  
doing exactly but just saw that his typo.

Cheers,  
Jan
