“Uninitialized constant” error when including a module
问题 I am trying to reference an association extension but it errors with: NameError (uninitialized constant User::ListerExtension): app/models/user.rb:2:in `<class:User>' Here is my implementation: app/models/user.rb class User < ActiveRecord::Base include ListerExtension has_and_belongs_to_many :roles, :uniq => true, :extend => Lister lib/lister.rb module ListerExtension def lister self.map(&:to_s).join(', ') end end I am using Rails v3.1.3. 回答1: Andrew Marshall has an excellent point about the