I have added options in application.rb:
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
and lib\functions.rb:
def some_lib
return "#######################################"
end
In controller I’m trying to call this function, but get the error:
undefined local variable or method `some_lib' for #<TodosController:0x49a3850>
How can I fix it?
In order to have rails autoload from the
libdir, you need to follow rails naming conventions.lib/functions.rb
Then you can
Functions.some_libOr
lib/functions.rb
Then
include Functionswhere you need your methods. This allows you to execute:some_lib