Sha256: 4ad3145c62c812bcbbf16035665ea9f3dddbfb87cef612b979e88248328106ba
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true module Decidim module Consultations # This module, when injected into a controller, ensures there's a # consultation available and deducts it from the context. module NeedsConsultation def self.enhance_controller(instance_or_module) instance_or_module.class_eval do helper_method :current_consultation end end def self.extended(base) base.extend Decidim::NeedsOrganization, InstanceMethods enhance_controller(base) end def self.included(base) base.include Decidim::NeedsOrganization, InstanceMethods enhance_controller(base) end module InstanceMethods # Public: Finds the current Consultation given this controller's # context. # # Returns the current Consultation. def current_consultation @current_consultation ||= detect_consultation end alias current_participatory_space current_consultation private def ability_context super.merge(current_consultation: current_consultation) end def detect_consultation request.env["current_consultation"] || organization_consultations.find_by(slug: params[:consultation_slug] || params[:slug]) end def organization_consultations @organization_consultations ||= OrganizationConsultations.new(current_organization).query end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems