Sha256: 3e4d1d30f93cd69ccd12377c607a64a113d80aad15269a714ac1450b1dbe5639

Contents?: true

Size: 1.04 KB

Versions: 19

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

# Abstract controller for all frontend controllers.
module PagesCore
  class FrontendController < ::ApplicationController
    include ApplicationHelper

    before_action :set_i18n_locale

    # Loads @root_pages and @rss_feeds. To automatically load these in your
    # own controllers, add the following line to your controller definition:
    #
    #   before_action :load_root_pages
    #
    def load_root_pages
      @root_pages = Page.roots.localized(@locale).published
      @rss_feeds = Page.where(feed_enabled: true).localized(@locale).published
    end

    private

    def legacy_locales
      {
        "nor" => "nb",
        "eng" => "en"
      }
    end

    def set_i18n_locale
      locale_param = params[:locale] || I18n.default_locale
      if legacy_locales[locale_param]
        locale_param = legacy_locales[locale_param]
      end
      I18n.locale = locale_param
    rescue I18n::InvalidLocale
      raise if Rails.application.config.consider_all_requests_local

      render_error 404
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pages_core-3.12.4 app/controllers/pages_core/frontend_controller.rb
pages_core-3.12.3 app/controllers/pages_core/frontend_controller.rb
pages_core-3.12.2 app/controllers/pages_core/frontend_controller.rb
pages_core-3.12.1 app/controllers/pages_core/frontend_controller.rb
pages_core-3.12.0 app/controllers/pages_core/frontend_controller.rb
pages_core-3.11.3 app/controllers/pages_core/frontend_controller.rb
pages_core-3.11.2 app/controllers/pages_core/frontend_controller.rb
pages_core-3.11.1 app/controllers/pages_core/frontend_controller.rb
pages_core-3.11.0 app/controllers/pages_core/frontend_controller.rb
pages_core-3.10.2 app/controllers/pages_core/frontend_controller.rb
pages_core-3.10.1 app/controllers/pages_core/frontend_controller.rb
pages_core-3.9.2 app/controllers/pages_core/frontend_controller.rb
pages_core-3.9.1 app/controllers/pages_core/frontend_controller.rb
pages_core-3.9.0 app/controllers/pages_core/frontend_controller.rb
pages_core-3.8.3 app/controllers/pages_core/frontend_controller.rb
pages_core-3.8.2 app/controllers/pages_core/frontend_controller.rb
pages_core-3.8.1 app/controllers/pages_core/frontend_controller.rb
pages_core-3.8.0 app/controllers/pages_core/frontend_controller.rb
pages_core-3.7.0 app/controllers/pages_core/frontend_controller.rb