Sha256: 33edc32bf600c20fbf81ffadeb43be5b5f01a080f066eb6d0325047bfbe054d0

Contents?: true

Size: 983 Bytes

Versions: 6

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true

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

    before_action :set_i18n_locale
    helper_method :page_param

    # 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(content_locale).published
      @rss_feeds = Page.where(feed_enabled: true)
                       .localized(content_locale)
                       .published
    end

    private

    def page_param
      params[:page].is_a?(String) ? params[:page] : 1
    end

    def set_i18n_locale
      I18n.locale = content_locale
    rescue I18n::InvalidLocale
      raise if Rails.application.config.consider_all_requests_local

      render_error 404
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pages_core-3.15.4 app/controllers/pages_core/frontend_controller.rb
pages_core-3.15.3 app/controllers/pages_core/frontend_controller.rb
pages_core-3.15.2 app/controllers/pages_core/frontend_controller.rb
pages_core-3.15.1 app/controllers/pages_core/frontend_controller.rb
pages_core-3.14.0 app/controllers/pages_core/frontend_controller.rb
pages_core-3.13.0 app/controllers/pages_core/frontend_controller.rb