-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open initiative print page in new tab
- Loading branch information
1 parent
ce70c09
commit fad049c
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
decidim-initiatives/app/controllers/concerns/decidim/initiatives/needs_initiative_type.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_support/concern" | ||
|
||
module Decidim | ||
module Initiatives | ||
# Common methods for elements that need specific behaviour when there is only one initiative type. | ||
module NeedsInitiativeType | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action :verify_initiative_type | ||
|
||
private | ||
|
||
def any_initiative_type? | ||
Decidim::InitiativesType.where(organization: current_organization).any? | ||
end | ||
|
||
def verify_initiative_type | ||
unless any_initiative_type? | ||
flash[:error] = "There needs to be an initiative type created by an administrator for initiatives to work" | ||
redirect_to decidim.root_path | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters