[Rails] link_to_remote where the url contain a javascript variable

Didier Prophete
2006-01-14T19:42:01Z

Ok, so I am basically trying to use ''link_to_remote'' and pass
the value
of a javascript variable as an argument. Something like that:

   link_to_remote "my_link",
                          :update => ''my_div'',
                          :url => { :action => "my_action", :var
=>
''my_var'' }

Basically, ''my_var'' is a javascript variable which I want to
pass to
''my_action''.

This, of course generates:
    <a href="#" onclick="new
Ajax.Updater(''my_div'',
''/xyz/my_action?var=my_var'', {asynchronous:true,
evalScripts:true});
return false;">my_link

But what I really want is this:
    <a href="#" onclick="new
Ajax.Updater(''my_div'',
''/xyz/my_action?var='' + my_var, {asynchronous:true,
evalScripts:true});
return false;">my_link

Notice the difference in the url:
   ''/slides/my_action?var=my_var''
vs:
   ''/slides/my_action?var='' + my_var
(I the second case, my_var is a javascript variable which gets appended
to the url)

I tried everything I could think of (escaping, etc...), but nothing
worked. Looking at the code, ''link_to_remote'' call
''remote_function'',
which eventually has this line:
  279:         function <<
"''#{url_for(options[:url])}''"

And the function ''url_for'' is going to try to url-encode
whatever I pass
to it... so whatever I try to escape gets ''url-encoded'' and
there is
nothing I can do...


Can anybody think of a solution for this ? (I can always write the
javascript on my own, but it is not as cool as using some rails features
:-)