简体   繁体   中英

extending Module trough ApplicationRecord Rails 5

I am trying to extend a module in the application_record.rb file in Rails 5.0.

The module is located in the /lib folder:

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

require 'update_live'

or put lib folder in the autoload path. In application.rb :

config.autoload_paths << Rails.root.join('lib')

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