Sha256: 54dcd93f3c64700535f49d6d2c08d265b455788e6b21c3582460aabedcf0dec2

Contents?: true

Size: 1.12 KB

Versions: 25

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

# Templates can be defined from the admin panel to store and use objects
# with given values and use them to create new ones using these values as default
#
# The model class we want to create these templates from must include the Templatable
# concern. A controller should be created to manage templates for the model,
# as well as the routes for the controller actions. The command classes to use in
# these actions should also be created to define the particular data management
# for the model's templates.
module Decidim
  module Templates
    class Template < ApplicationRecord
      belongs_to :organization,
                 foreign_key: "decidim_organization_id",
                 class_name: "Decidim::Organization"

      belongs_to :templatable, foreign_type: "templatable_type", polymorphic: true, optional: true

      before_destroy :destroy_templatable

      validates :name, presence: true

      def resource_name
        [templatable_type.demodulize.tableize.singularize, "templates"].join("_")
      end

      def destroy_templatable
        templatable.destroy
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-templates-0.26.10 app/models/decidim/templates/template.rb
decidim-templates-0.26.9 app/models/decidim/templates/template.rb
decidim-templates-0.26.8 app/models/decidim/templates/template.rb
decidim-templates-0.26.7 app/models/decidim/templates/template.rb
decidim-templates-0.26.5 app/models/decidim/templates/template.rb
decidim-templates-0.26.4 app/models/decidim/templates/template.rb
decidim-templates-0.26.3 app/models/decidim/templates/template.rb
decidim-templates-0.26.2 app/models/decidim/templates/template.rb
decidim-templates-0.26.1 app/models/decidim/templates/template.rb
decidim-templates-0.26.0 app/models/decidim/templates/template.rb
decidim-templates-0.26.0.rc2 app/models/decidim/templates/template.rb
decidim-templates-0.26.0.rc1 app/models/decidim/templates/template.rb
decidim-templates-0.25.2 app/models/decidim/templates/template.rb
decidim-templates-0.25.1 app/models/decidim/templates/template.rb
decidim-templates-0.25.0 app/models/decidim/templates/template.rb
decidim-templates-0.25.0.rc4 app/models/decidim/templates/template.rb
decidim-templates-0.25.0.rc3 app/models/decidim/templates/template.rb
decidim-templates-0.25.0.rc2 app/models/decidim/templates/template.rb
decidim-templates-0.25.0.rc1 app/models/decidim/templates/template.rb
decidim-templates-0.24.3 app/models/decidim/templates/template.rb