我在Ruby on Rails中处理奇怪的问题。
在 app / lib / cml.rb 中我有:
module CML
class << self
attr_accessor :scheduler
def configure
yield self
true
end
end
end
然后我在 config / initializers / cml.rb :
CML.configure do |config|
config.scheduler = "hey"
end
应用程序/控制器/ example_controller.rb
class ExampleController < ApplicationController
def action1
logger.debug "Scheduler: #{CML.scheduler}"
puts ""
end
end
应用程序/配置/ routes.rb中
Rails.application.routes.draw do
get '/action1', to: 'example#action1'
end
问题:
预期行为:在日志中我看到&#34;调度程序:嘿&#34;。
现实:在日志中,我看到&#34;调度程序:&#34; (在byebug中我看到它没有了)
使用示例应用的Github回购:https://github.com/luki215/rails-module-error
我做错了什么?我看到这种配置常用于几个宝石,这些宝石工作得很好。谢谢!