3

複数のモデル間でいくつかの動作を共有したいと考えています。少なくとも 2 つのアプローチがあります。

1) ActiveSupport::Concern:

module Contentable
  extend ActiveSupport::Concern
  module InstanceMethods
    #some shared behavior(validations, callbacks, etc)
  end
end

class Content < ActiveRecord::Base
  include Contentable
end

2) モデル (クラス) 継承:

class Content < ActiveRecord::Base 
   #some shared behavior(validations, callbacks, etc)
end

class Article < Content  
end

最初の方法の唯一の利点は、必要な数のモジュールを含めることができることです。両方のアプローチのその他の利点/欠点はありますか?

4

0 に答える 0