<img onclick> vs link_to_remote()

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

Hi Kad,

please try:

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

Cheers,
Jan

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?

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