Sha256: 9b422948990dbbc8c12aff7af9e7c4141d255e17bff6f8314476401ac499471d
Contents?: true
Size: 784 Bytes
Versions: 2
Compression:
Stored size: 784 Bytes
Contents
# frozen_string_literal: true require "active_support/concern" module Decidim # A concern with the features needed when you want a model to have a category. module HasCategory extend ActiveSupport::Concern included do has_one :categorization, as: :categorizable has_one :category, through: :categorization validate :category_belongs_to_organization def previous_category return if categorization.versions.count <= 1 Decidim::Category.find_by(id: categorization.versions.last.reify.decidim_category_id) end private def category_belongs_to_organization return unless category errors.add(:category, :invalid) unless feature.categories.where(id: category.id).exists? end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
decidim-core-0.10.1 | lib/decidim/has_category.rb |
decidim-core-0.10.0 | lib/decidim/has_category.rb |