class PagesController < ForestController
  before_action :set_page, only: [:show]

  def show
    unless @page
      raise ActionController::RoutingError.new('Not Found')
    end
    authorize @page

    if @page.redirect.present?
      return redirect_to @page.redirect
    end

    @body_classes << "page--#{@page.slug}"
  end

  def edit
    @page = Page.where(path: params[:page_path]).try(:first)
    if @page
      return redirect_to edit_admin_page_path(@page)
    else
      return redirect_to admin_pages_path
    end
  end

  private

    def set_page
      @page = Page.find_by_path(params[:page_path].presence || 'home')
    end
end

class PagesController < ForestController
  before_action :set_page, only: [:show]

  def show
    unless @page
      logger.error("[Forest][Error] 404 page not found. Looked for path \"#{request.fullpath}\"")
      return render 'errors/not_found'
    end
    authorize @page

    if @page.redirect.present?
      return redirect_to @page.redirect
    end

    @body_classes << "page--#{@page.slug}"
  end

  def edit
    @page = Page.where(path: params[:page_path]).try(:first)
    if @page
      return redirect_to edit_admin_page_path(@page)
    else
      return redirect_to admin_pages_path
    end
  end

  private

    def set_page
      @page = Page.find_by_path(params[:page_path].presence || 'home')
    end
end

Update pages controller to render not found template instead of error
Update pages controller to render not found template instead of error

Raising ActionController::RoutingError spits out a bunch of junk
in the rails logs. Rendering the not found page directly avoids this
and makes it easier to filter out from your logs, thus making it easier
to discover other issues.
