Sha256: d3cfe6cd5f10909a712cbb8764a13fa525f865d0b620568f81d10f8bd3856d18

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8

# 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

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 app/controllers/pages_core/frontend_controller.rb