Ok, now that I understand your question, I'll answer according....
First option:
Edit your files:
- config/environments/development.rb
- config/environments/test.rb
- config/environments/production.rb
and you have to write the host like:
default_url_options[:host] = 'www.example.com'
then you can create a javascript within your assets like app/assets/javascript/test.js.erb, make sure to add the .erb extension so ruby code is executed first when compiling the javascript and add the code:
<% environment.context_class.instance_eval { include Rails.application.routes.url_helpers } %>
var absURL = '<%= root_url %>';
Have in mind that because its an asset, it will be precompile when deploying once, and the minified version will be served for every request (so the ruby code will be executed just when deploying).
Option 2:
you can add a route of your choice in config/routes.rb like:
match 'my_js', to: 'home#my_js'
and then you can create a view in your home controller: app/views/home/my_js.js.rb and add the ruby code right there:
var absURL = '<%= root_url %>';
Be sure to include the actionpack-page_caching gem in order to generate a cache for your action, so it gets compiled on first request and then it will just serve the compiled version on all the other requests (although it won't minify the javascript, so the assets may be a better solution)