获取环境的根地址

时间:2013-12-01 10:05:38

标签: ruby-on-rails

有没有办法从配置文件夹中获取rails应用程序的根URL?另外,您可以获得运行服务器的端口吗?

1 个答案:

答案 0 :(得分:0)

database.yml

development:
    adapter: mysql
    encoding: utf8
    database: db_development
    host: https://example.com
    port: XXX
    username: root
    password:

然后,从 config \ initializers

调用它
require "yaml"
config = YAML.load_file(Rails.root.join("config","database.yml"))[Rails.env]
config["port"] => XXX
config["host"] => https://example.com