This means app-name.heroku.com.
Note this is different from Rails.application.class.parent_name
.
Rails.application.class.parent_name
is defined in the application.
Working in Rails 3.
By default, a Heroku app is available at its Heroku domain, which has the form [name of app]. herokuapp.com . For example, an app named serene-example-4269 is hosted at serene-example-4269.herokuapp.com .
After a second or two, Heroku will have created a new app and have chosen a random name for it. This ensures that your app name is globally unique across the entire Heroku platform, making it possible to use the app name as a part of your domain name.
The solution with ENV['URL']
will only work during requests.
So if you need to know the app id outside a request, you's set a config variable like this
heroku config:add APP_NAME=<myappname> --app <myappname>
And enable lab feature that allows you to use them during compile
heroku labs:enable user-env-compile -a myapp
And now I have my app name available here:
ENV["APP_NAME"] # '<myappname>'
This is handy if you want to load different config file (say with oauth credentials) based on the app's name or id.
Heroku actually sets a URL variable in the environment by default
app_name = ENV['URL'].split(".").first
Referenced here: http://devcenter.heroku.com/articles/config-vars and http://ididitmyway.heroku.com/past/2010/11/9/sinatra_settings_and_configuration/
update: actually the URL variable might not be there by default, but you could always add an environment variable "app name" a priori, unless you were trying to avoid that approach all together.
update 2: indeed, the other, obvious but limiting approach, would be to grab the domain off the request variable, but this limits you to your controller. http://guides.rubyonrails.org/action_controller_overview.html#the-request-object
Rails.application.config.session_options[:key].sub(/^_/,'').sub(/_session/,'')
=> "test-app"
that's the name of the Rails app, as it was spelled when you did 'rails new app-name'
Using this, you could do this:
class << Rails.application
def name
Rails.application.config.session_options[:key].sub(/^_/,'').sub(/_session/,'')
end
end
Rails.application.name
=> 'test-app'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With