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

有帮助吗?

解决方案

in case lib/app_lib.rb is a module, you need to include it into your application controller!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top