Skip to content

Instantly share code, notes, and snippets.

@openscript
Created November 9, 2016 11:44
Show Gist options
  • Save openscript/7199e9b5515c45a4b7bc05d23dd7e9aa to your computer and use it in GitHub Desktop.
Save openscript/7199e9b5515c45a4b7bc05d23dd7e9aa to your computer and use it in GitHub Desktop.
class PagesController < ApplicationController
def show
@page = nil
current = nil
params[:slug].split('/').reverse.each do |s|
if current
current = current.parent.where(slug: s)
else
@page = Page.find_by(slug: s)
current = @page
end
render status: 404 unless @page || current
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment