Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
simplify PagesController
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschilling committed Jul 11, 2012
1 parent 2f0db91 commit 6d67e93
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions app/controllers/pages_controller.rb
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

0 comments on commit 6d67e93

Please sign in to comment.