If you can''t alter the link_to_remote, you might drop down below the
Rails helper function and use Prototype to replace the href in the
particular <a> tag. It depends on when you get Js_Variable. If you
know it prior to generating the page, you could have:
<a href="/foo" id="unique_link_id"
class="ajax_link">Do it, do it now</a>
Then in javascript, you insert the onclick() function that normally
gets generated by the link_to_remote helper.
$(''unique_link_id'').onclick = function () {
url = your_javascript_url_variable;
new Ajax.Request(url, { method: ''post'',
postBody:
''yadda=true&yadda2=false'',
onComplete: ... } );
}
I think that should work, but I''m still learning javascript. Look at
the decent documentation over at script.aculo.us for prototype API. A
web app I''m developing uses Behaviour + prototype and it works well so
far. Behaviour lets you use general CSS selectors for assigning those
onclick (and other) behaviors. The prototype $ function seems limited
to an id. So with Behaviour, I could specify a whole class of <a> tags
(e.g. ''.ajax_link'') to get different urls based on a local
javascript
variable or array. Behaviour also fires off the (onclick) replacements
on loading. I think it''s a pretty nice way to do things, as long as
you don''t need instantaneous while-loading interaction.
On 9/7/05, Bogdan Ionescu
<bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Is there a way in which I could alter the resulting link based on a
> javascript variable?
> Something like link_to_remote(:url=>{:name=>Js_Variable})
> I''m interested in passing a value read from the user, but I
don''t want to
> use a form_remote_tag to do that.
>
> Bogdan