我的lib中有一个ActiveRecord类设置(自动加载)
class Settings < ActiveRecord::Base
cattr_accessor :defaults
@@defaults = {}.with_indifferent_access
...
我定义了初始化程序'settings.rb',以设置一些默认值
Settings.defaults[:admin_email] = 'john.doe@acme.com'
#.....
运行控制台时,我应该看到默认值,但它是空的:
# expected Settings.admin_email => 'john.doe@acme.com'
Settings.admin_email => {}
如果我在settings.rb中插入调试器语句,那么我可以停止,甚至执行 Settings.defaults [:admin_email] ='john.doe@acme.com'但是 Settings.admin_email =&gt; {}
然后如果我在控制台中运行: Settings.defaults [:admin_email] ='john.doe@acme.com' Settings.admin_email =&gt; 'john.doe@acme.com'
似乎初始化代码已执行,但类变量未保存...是否与Rails 3.2类变量初始化相关