in case lib/app_lib.rb
is a module, you need to include it into your application controller!
How do I make a library available to the entire application in Rails4
-
20-07-2023 - |
题
I have a number of methods that I would like to make available to the entire application. Based on what I read and researched, I did the following:
1. Created a lib/app_lib.rb
and defined some methods in it.
2. In config/application.rb, I added the following lines:
config.assets.enabled = true
config.autoload_paths += %W(#{config.root}/lib)
This however is not working, as when I try to call one of the methods in any of the controllers or views, I get the error message:
undefined local variable or method ....
This is for Rails 4.1
解决方案
不隶属于 StackOverflow