This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f0db91
commit 6d67e93
Showing
1 changed file
with
3 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,13 @@ | ||
class PagesController < ApplicationController | ||
rescue_from ActionView::MissingTemplate, with: :missing | ||
|
||
def show | ||
@page_name = params[:page_name].to_s.gsub(/\W/,'') | ||
|
||
unless partial_exists? @page_name | ||
render 'missing', status: 404 | ||
end | ||
end | ||
|
||
private | ||
|
||
def partial_exists?(partial) | ||
VALID_PARTIALS.include?(partial) | ||
end | ||
|
||
def self.find_partials | ||
Dir.glob(Rails.root.join('app', 'views', 'pages', '_*.haml')).map do |file| | ||
file = Pathname.new(file).basename.to_s | ||
# Strip leading _ and then everything from the first . to the end of the name | ||
file.sub(/^_/, '').sub(/\..+$/, '') | ||
end | ||
def missing | ||
render 'missing', status: 404 | ||
end | ||
|
||
# Do this once on boot | ||
VALID_PARTIALS = PagesController.find_partials | ||
end |