app/controllers/alchemy/base_controller.rb in alchemy_cms-4.6.7 vs app/controllers/alchemy/base_controller.rb in alchemy_cms-5.0.0.beta1

- old
+ new

@@ -6,29 +6,30 @@ class BaseController < ApplicationController include Alchemy::ConfigurationMethods include Alchemy::AbilityHelper include Alchemy::ControllerActions include Alchemy::Modules - include Alchemy::SSLProtection protect_from_forgery before_action :mailer_set_url_options before_action :set_locale - helper 'alchemy/admin/form' + helper "alchemy/admin/form" rescue_from CanCan::AccessDenied do |exception| permission_denied(exception) end private # Sets +I18n.locale+ to current Alchemy language. # def set_locale - ::I18n.locale = Language.current.locale + return unless Language.current + + ::I18n.locale = Language.current&.locale end def not_found_error!(msg = "Not found \"#{request.fullpath}\"") raise ActionController::RoutingError, msg end @@ -58,36 +59,36 @@ handle_redirect_for_guest end end def handle_redirect_for_user - flash[:warning] = Alchemy.t('You are not authorized') + flash[:warning] = Alchemy.t("You are not authorized") if can?(:index, :alchemy_admin_dashboard) redirect_or_render_notice else - redirect_to('/') + redirect_to("/") end end def redirect_or_render_notice if request.xhr? respond_to do |format| format.js do render plain: flash.discard(:warning), status: 403 end format.html do - render partial: 'alchemy/admin/partials/flash', - locals: {message: flash[:warning], flash_type: 'warning'} + render partial: "alchemy/admin/partials/flash", + locals: { message: flash[:warning], flash_type: "warning" } end end else redirect_to(alchemy.admin_dashboard_path) end end def handle_redirect_for_guest - flash[:info] = Alchemy.t('Please log in') + flash[:info] = Alchemy.t("Please log in") if request.xhr? render :permission_denied else store_location redirect_to Alchemy.login_path @@ -96,10 +97,10 @@ # Logs the current exception to the error log. def exception_logger(error) Rails.logger.error("\n#{error.class} #{error.message} in #{error.backtrace.first}") Rails.logger.error(error.backtrace[1..50].each { |line| - line.gsub(/#{Rails.root.to_s}/, '') + line.gsub(/#{Rails.root}/, "") }.join("\n")) end end end