带有 create_time_zone_conversion_attribute 的 nil.include? 错误

问题描述

     一个rails 项目,用 rufus_scheduler 来定时发邮件。 如果不访问页面,rufus_scheduler 正常运行;但一旦访问页面,就会出现 nil.include?错误,call_trace上有create_time_zone_conversion_attribute。

堆栈:

scheduler caught exception :
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?'
D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods'
D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:71:in `each'
D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods'
D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:242:in `method_missing'
D:/Users/piboye/workspace/mail_promote/config/initializers/task_schedule.rb:18:in `setup_cron'

 

问题分析:

   估计是 rufus_scheduler 修改了默认的时区设置(就是 config.time_zone = 'UTC' 被重新赋值了)

 

解决办法:

修改 config/environment.rb 文件,

在 config.time_zone = 'UTC' 下面添加:

config.active_record.default_timezone = :utc

这样就把 active_record 默认时区改回成 UTC了。

你可能感兴趣的:(conversion)