Sha256: d1f4dac956c1e0f4188ec378218a010f900e0f0d68b58aefca457d94695c649a

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

class PagesController < ApplicationController
  before_action :find_structure, only: [:show]

  caches_page :show

  def show
    template = "pages/#{@structure.slug.gsub(/[^a-z]/, '_')}"
    template = 'pages/show' unless lookup_context.exists?(template)

    render template: template
  end

  def not_found_sample
    render_404
  end

  def service_unavailable
    render_cached_page(503)
  end

  def check_ip
    render json: request.location.try(:data).try(:as_json)
  end

  protected

  def find_structure
    @structure = Structure.visible.with_type(StructureType.page).where(slug: params[:slug]).first
    raise ActiveRecord::RecordNotFound, "Structure #{params[:slug]} not found" if @structure.nil?
    if @structure.service_page?
      raise ActiveRecord::RecordNotFound, "Structure #{params[:slug]} is a service page!"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/controllers/pages_controller.rb