在Heroku上运行Rails时,如何获得应用程序名称? [英] How do you get the app name when running Rails on Heroku?

查看:124
本文介绍了在Heroku上运行Rails时,如何获得应用程序名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这意味着app-name.heroku.com。



请注意,这与 Rails.application.class.parent_name $ b

Rails.application.class.parent_name 在应用程序中定义。



在Rails 3中工作

解决方案

Heroku实际上在环境中设置了一个URL变量默认

  app_name = ENV ['URL']。split(。)。first 

引用此处: 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 Rails.application.class.parent_name.

Rails.application.class.parent_name is defined in the application.

Working in Rails 3.

解决方案

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

这篇关于在Heroku上运行Rails时,如何获得应用程序名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆