在Heroku上运行Rails时,如何获得应用程序名称? [英] How do you get the app name when running Rails on Heroku?
问题描述
这意味着app-name.heroku.com。
请注意,这与 在Rails 3中工作 Heroku实际上在环境中设置了一个URL变量默认 引用此处: http://devcenter.heroku.com/articles/config-vars 和 http://ididitmyway.heroku.com/past/2010/11/9/sinatra_settings_and_configuration/ 更新:实际上,默认情况下,URL变量可能不存在,但您可以始终先添加环境变量app name,un更少的是你试图避免这种方法在一起。 更新2:确实,另一个显而易见的限制方法是抓取该域关闭请求变量,但是这限制了你的控制器。 http://guides.rubyonrails.org/action_controller_overview.html#the-request-object This means app-name.heroku.com. Note this is different from Working in Rails 3. Heroku actually sets a URL variable in the environment by default 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 这篇关于在Heroku上运行Rails时,如何获得应用程序名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Rails.application.class.parent_name $ c不同$ c $。
$ b Rails.application.class.parent_name
在应用程序中定义。
app_name = ENV ['URL']。split(。)。first
Rails.application.class.parent_name
.Rails.application.class.parent_name
is defined in the application.app_name = ENV['URL'].split(".").first