我想为整个应用程序提供许多方法。根据我阅读和研究的内容,我做了以下工作:
1. Created a lib/app_lib.rb
并在其中定义了一些方法。
2. In config/application.rb, I added the following lines:
config.assets.enabled = true
config.autoload_paths += %W(#{config.root}/lib)
但是,这不起作用,因为当我尝试调用任何控制器或视图中的方法之一时,我收到错误消息:
undefined local variable or method ....
这适用于 Rails 4.1