Created
November 9, 2016 11:44
-
-
Save openscript/7199e9b5515c45a4b7bc05d23dd7e9aa to your computer and use it in GitHub Desktop.
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
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