Sha256: f164cba830cc327aa420be686ad73b0a95f34eb9431a8a01dc61cc3ebfe649a4

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

module Qbrick
  class PagesController < ::ApplicationController
    respond_to :html
    before_action :set_locale
    before_action :find_page_by_path, only: :show

    def index
      @search = params[:search]
      return if @search.blank?

      @pages = Qbrick::Page.unscoped.published.content_page.search(@search)
    end

    def show
      if redirect_page?
        session[:qbrick_referrer] = @page.id
        redirect_to @page.redirect_url
      elsif @page.present?
        respond_with @page
      elsif @page.blank? && respond_to?(:handle_404)
        handle_404
      else
        raise ActionController::RoutingError, 'Not Found'
      end
    end

    def lookup_by_id
      @page = Page.find(params[:id])
      redirect_to "/#{@page.url}"
    end

    private

    def set_locale
      new_locale = params[:locale] || session['frontend_locale'] || I18n.locale

      return I18n.locale if I18n.locale == new_locale || !I18n.locale_available?(new_locale)

      session['frontend_locale'] = new_locale.to_s
      I18n.locale = new_locale
    end
    alias frontend_locale set_locale

    def redirect_page?
      @page.present? && @page.redirect? && @page.redirect_url.present?
    end

    def find_page_by_path
      @page = Qbrick::Page.published.find_by_path params[:url].to_s
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
qbrick-2.7.1 app/controllers/qbrick/pages_controller.rb
qbrick-2.7 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.10 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.9 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.8 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.7 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.6 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.5 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.4 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.3 app/controllers/qbrick/pages_controller.rb
qbrick-2.6.2 app/controllers/qbrick/pages_controller.rb