使用其他类扩展滑轨模型

问题描述

| 我正在编写要扩展模型的gem。我尝试将我的gem中的类定义为:
class usermodel < ActiveRecord::Base
然后用户模型为:
class User < Adauth::usermodel
但这导致Active Record抛出表未找到错误,因为它使用usermodel而不是User作为模型名称。 我无法指定模型名称,因为我打算让一个命名生成器使用User作为认模型来创建模型。 我假设无法从定义行中的2个类/模块继承,那么如何将Adauth :: usermodel中的所有方法导入模型中?     

解决方法

我不知道这是否是解决您问题的最佳解决方案,但是您可以尝试使用mixins。 使用所需的所有方法定义模块UserModel。
module Adauth
  module UserModel
    # methods go here
  end
end
然后在定义模型时:
class User < ActiveRecord::Base
  include Adauth::UserModel
end