Sha256: 5cd37c5ff91edcfc5ee9890f2a901c27a82254c3840c8686fb28ff55c935fd76
Contents?: true
Size: 1.1 KB
Versions: 64
Compression:
Stored size: 1.1 KB
Contents
module Tenon module TenonContent def self.included(base) base.extend(ClassMethods) end module ClassMethods def tenon_content(content_field, i18n: false) Tenon::TenonContentBuilder.add_assoc(self, content_field) define_method("#{content_field}_i18n?") { i18n } if i18n && Tenon.config.languages Tenon.config.languages.each do |title, lang| Tenon::TenonContentBuilder.add_assoc(self, "#{content_field}_#{lang}") end end end end end class TenonContentBuilder class << self def add_assoc(klass, content_field) assoc = "#{content_field}_tenon_content_rows".to_sym args = [assoc, -> { where(item_method: content_field) }, assoc_opts] klass.send(:has_many, *args) klass.send(:accepts_nested_attributes_for, assoc, allow_destroy: true) end private def assoc_opts { class_name: 'Tenon::TenonContent::Row', as: :item, dependent: :destroy } end end end end ActiveRecord::Base.send(:include, Tenon::TenonContent)
Version data entries
64 entries across 64 versions & 1 rubygems