Ruby on rails 关系不存在ActiveSupport::Concern

Ruby on rails 关系不存在ActiveSupport::Concern,ruby-on-rails,activerecord,activesupport,activesupport-concern,Ruby On Rails,Activerecord,Activesupport,Activesupport Concern,我有一个简单的模块,它包含在我的模型中 module Inputable extend ActiveSupport::Concern included do has_many :inputs, as: :inputable, dependent: :destroy end end class Product < ActiveRecord::Base include Inputable end 我的代码有什么问题?请确保已生成输入模型并运行迁移 另外,当我

我有一个简单的模块,它包含在我的模型中

module Inputable
  extend ActiveSupport::Concern

  included do
    has_many :inputs, as: :inputable, dependent: :destroy
  end
end

 class Product < ActiveRecord::Base
    include Inputable
end

我的代码有什么问题?

请确保已生成
输入模型并运行迁移

另外,当我使用
included
hook时,它看起来更像这样:

module Inputable
  extend ActiveSupport::Concern

  self.included(base)
    base.class_eval do 
      has_many :inputs, as: :inputable, dependent: :destroy
    end
  end

end

我想知道你使用的语法是否适合你。快乐元编程

您是否生成了输入模型并运行了
rake db:migrate
?愚蠢的问题,但我想我会问。你说得对,我没有看到你的输入迁移代码和输入模型吗?ActiveSupport::Concern的整个想法是删除(或隐藏)这些
self.included(base)
方法并使它们更具可读性:@sebastianvommer-谢谢你的链接!我想我是那些避开顾虑的人中的一员——因此我不熟悉语法糖。所以,再次感谢你的指点。
module Inputable
  extend ActiveSupport::Concern

  self.included(base)
    base.class_eval do 
      has_many :inputs, as: :inputable, dependent: :destroy
    end
  end

end