Can I do somehting like this in Rails ?
module Authored
belongs_to :user
attr_accessible creation_date
end
class Line < ActiveRecord::Base
include Authored
end
class Document < ActiveRecord::Base
include Authored
end
class User < ActiveRecord::Base
has_many :creations, :class_name => 'Authored'
end
Or do I need to use simple inheritance, even if my Authored classes have different class hierarchies ?
module Authored
extend ActiveSupport::Concern
included do
belongs_to :user
attr_accessible :creation_date
end
end
class Line < ActiveRecord::Base
include Authored
end
class Document < ActiveRecord::Base
include Authored
end
For more info on ActiveSupport::Concern
, http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With