vol1ura/Sat_9am_5km

View on GitHub
app/controllers/pages_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

class PagesController < ApplicationController
  ALLOWED_PAGES = %w[index about rules support additional-events privacy-policy robots].freeze

  before_action :validate_page

  def show
    render template: "pages/#{page_name}"
  end

  private

  def page_name
    @page_name ||= params[:page]&.to_s || 'index'
  end

  def validate_page
    render file: 'public/404.html', status: :not_found if ALLOWED_PAGES.exclude?(page_name)
  end
end