简体   繁体   中英

How to create a module in lib folder in Ruby on Rails?

I want to create a module in /lib folder & access that form my controllers. There are several solutions available in different websites, but modules are not loading.

You need to add:

config.autoload_paths += %W(#{config.root}/lib)

to your config/application.rb

And then:

require 'file_name'

in your controller. That works for me (Rails 4).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM