how to get domain url in initializer file, rails

domain-name, initializer, ruby-on-rails

Solution

i just changed one of my apps to a staging environment. i couldn't get the socket to work.

heroku config:add RAILS_ENV=staging --app myapp-staging
heroku config:add RACK_ENV=staging --app myapp-staging

and then i made a staging.rb file inside my environments folder (i just copied and pasted everything from my production file) and rails was able to infer the method

Rails.env.staging?

in my initializer

Problem

i was wondering if it was possible to get the domain url ie ``` localhost or myapp.heroku.com ``` from an initializer file? i believe the ``` request.url ``` and the request methods only work in controllers. is there an equivalent to the javascript ``` document.domain ``` that i could do in an initializer file? or could i embed the .rb file with javascript? or other alternatives to the request object? ive tried a number of things that don't work such as ``` Rails.root ``` and am having trouble trying to figure it out. thank you = )

Original source