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 🙂
Maybe a bit hackish solution, but i have a configuration-file like described here, and so you could do something like, inside a
config.yml:and when you build your Ajaxrequest, you could write
But it still looks like there should be a cleaner way to solve this 😉