English 中文(简体)
我在“我”中做了什么事。 CONFIG yml file in Railways 3?
原标题:What have I done wrong in my APP_CONFIG yml file in Rails 3?

使用铁路3.1.1。 这是我在<代码>config/app_config.yml上的阿盟文。

development: &non_production_settings
  site_url: http://localhost:3000

这是我被剥夺的<代码>config/application.rb。

require File.expand_path( ../boot , __FILE__)

# load app_config.yml  
require  yaml   
APP_CONFIG = YAML.load(File.read(File.expand_path( ../app_config.yml , __FILE__)))

require  rails/all 

我尝试采用<代码>site_url。 在我的模板中,甚至还击退了它,但它仍在回去:

<%= abort(APP_CONFIG[:site_url]) %> #returns: can t convert nil into String 

我做了哪些错误? 感谢!

最佳回答

我必须把该守则推向一个轨道,并为它增加一个环境:

# config/application.rb
require File.expand_path( ../boot , __FILE__)

require  rails/all 

# load app_config.yml  
require  yaml   
APP_CONFIG = YAML.load(File.read(File.expand_path( ../app_config.yml , __FILE__)))[Rails.env]

之后,全球不断接触:

APP_CONFIG[ site_url ]
问题回答

根据您的黄玉米档案的格式,因此 par子认为:

{"development"=>{"site_url"=>"http://localhost:3000"}}

第二行的内附因素使网站“url等级”在发展范围之内。 此外,它们通过符号直接获得。

因此,进入网站_url,将采用你制作的午餐格式

APP_CONFIG[ development ][ site_url ]




相关问题
Remove ActiveRecord in Rails 3

Now that Rails 3 beta is out, I thought I d have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB ...

When will you upgrade your app to Rails 3? [closed]

Now that the Rails 3 beta is here, let s take a little straw poll. Please tell us briefly what your application does and when you will upgrade it to Rails 3. Or, if you re not planning on upgrading ...

Bundler isn t loading gems

I have been having a problem with using Bundler and being able to access my gems without having to require them somewhere, as config.gem used to do that for me (as far as I know). In my Rails 3 app, I ...

bypass attr_accessible/protected in rails

I have a model that, when it instantiates an object, also creates another object with the same user id. class Foo > ActiveRecord::Base after_create: create_bar private def create_bar Bar....

concat two fields activerecord

I m so used to oracle where you can simply concat(field1, , field2) but if I m using activerecord to find the field1 and field2, and I need a space in between, how do I accomplish this? Cheers ...

热门标签