[英]extending Module trough ApplicationRecord Rails 5
I am trying to extend a module in the application_record.rb file in Rails 5.0. 我试图在Rails 5.0中的application_record.rb文件中扩展一个模块。
The module is located in the /lib folder: 该模块位于/ lib文件夹中:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
extend UpdateLive
extend UpdatePre
end
When trying to use a method in one of the Models I get the following error: 当尝试在其中一个模型中使用方法时,我收到以下错误:
NameError: uninitialized constant ApplicationRecord::UpdateLive
I can't seem to figure out what I am doing wrong, or if I forgot a step? 我似乎无法弄清楚我做错了什么,或者我忘记了一步?
You need to require update_live in your ApplicationRecord 您需要在ApplicationRecord中要求update_live
require 'update_live'
or put lib
folder in the autoload path. 或者将lib
文件夹放在自动加载路径中。 In application.rb
: 在application.rb
:
config.autoload_paths << Rails.root.join('lib')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.