Dynamic path in new.AjaxRequest with Rails

Posted by Robbie on Stack Overflow See other posts from Stack Overflow or by Robbie
Published on 2010-05-27T15:50:29Z Indexed on 2010/05/28 8:51 UTC
Read the original article Hit count: 195

Filed under:
|
|

Hello, I was wondering if there's anyway to get a 'dynamic path' into a .js file through Ruby on Rails.

For example, I have the following:

new Ajax.Request('/tokens/destroy/' + GRID_ID, {asynchronous:true, evalScripts:true, onComplete:function(request){load('26', 'table1', request.responseText)}, parameters:'token=' + dsrc.id + '&authenticity_token=' + encodeURIComponent(AUTH_TOKEN)})

The main URL is '/tokens/destroy/:id', however on my production server this app runs as a sub folder. So the URL for this ajax call needs to be '/qrpsdrail/tokens/destroy/:id'

The URL this is being called from would be /grids/1 or /qrpsdrail/grids/1

I could, of course, do ../../path -- but that seems a bit hackish. It is also dependent on the routing never changing, which at this stage I can't guarantee. I'm just interested in seeing what other solutions there might be to this problem.

Thanks in advance :)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about AJAX