Skip to content

Commit

Permalink
Refactor Bootstrapping Redirects into concerns
Browse files Browse the repository at this point in the history
This should alleviate some of CodeClimate's concerns.
  • Loading branch information
mamhoff committed Mar 30, 2020
1 parent f96820c commit 669943d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
5 changes: 1 addition & 4 deletions app/controllers/alchemy/admin/layoutpages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ module Admin
class LayoutpagesController < Alchemy::Admin::BaseController
authorize_resource class: :alchemy_admin_layoutpages

before_action unless: -> { Alchemy::Language.current }, only: :index do
flash[:warning] = Alchemy.t('Please create a language first.')
redirect_to admin_languages_path
end
include Alchemy::Admin::LanguageNeededRedirect

helper Alchemy::Admin::PagesHelper

Expand Down
5 changes: 1 addition & 4 deletions app/controllers/alchemy/admin/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
module Alchemy
module Admin
class NodesController < Admin::ResourcesController
before_action unless: -> { Alchemy::Language.current }, only: :index do
flash[:warning] = Alchemy.t('Please create a language first.')
redirect_to admin_languages_path
end
include Alchemy::Admin::LanguageNeededRedirect

def index
@root_nodes = Node.language_root_nodes
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ class PagesController < Alchemy::Admin::BaseController
authorize! :index, :alchemy_admin_pages
end

before_action unless: -> { Alchemy::Language.current }, only: :index do
flash[:warning] = Alchemy.t('Please create a language first.')
redirect_to admin_languages_path
end
include Alchemy::Admin::LanguageNeededRedirect

before_action :set_translation,
except: [:show]
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/concerns/alchemy/admin/language_needed_redirect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Alchemy
module Admin
module LanguageNeededRedirect
extend ActiveSupport::Concern

included do
before_action unless: -> { Alchemy::Language.current }, only: :index do
flash[:warning] = Alchemy.t('Please create a language first.')
redirect_to admin_languages_path
end
end
end
end
end

0 comments on commit 669943d

Please sign in to comment.