Ruby on rails 使用另一个类扩展rails模型

Ruby on rails 使用另一个类扩展rails模型,ruby-on-rails,gem,Ruby On Rails,Gem,我正在写一个gem,我想扩展一个模型。我尝试在我的gem中将类定义为: class UserModel < ActiveRecord::Base class-UserModel

我正在写一个gem,我想扩展一个模型。我尝试在我的gem中将类定义为:

class UserModel < ActiveRecord::Base
class-UserModel
然后用户模型为:

class User < Adauth::UserModel
class用户
但这导致Active Record抛出一个table not found错误,因为它使用UserModel not User作为模型名

我无法指定模型名称,因为我希望使用命名生成器以用户作为默认值创建模型


我假设不可能从定义行中的2个类/模块继承,那么如何将所有方法从Adauth::UserModel导入到模型中?

我不知道这是否是解决问题的最佳方案,但您可以尝试使用mixin

使用所需的所有方法定义模块UserModel

module Adauth
  module UserModel
    # methods go here
  end
end
然后在定义模型时:

class User < ActiveRecord::Base
  include Adauth::UserModel
end
class用户
我不知道这是否是解决您问题的最佳方案,但您可以尝试使用mixin

使用所需的所有方法定义模块UserModel

module Adauth
  module UserModel
    # methods go here
  end
end
然后在定义模型时:

class User < ActiveRecord::Base
  include Adauth::UserModel
end
class用户