class Page
def find_by_path(path, can_view_drafts = false, clean = true)
def find_by_path(path, can_view_drafts = false, clean = true) return nil if virtual? path = clean_path(path) if clean my_path = self.path if (my_path == path) && (published? || hidden? || can_view_drafts) return self elsif path =~ /^#{Regexp.quote(my_path)}([^\/]*)/ slug_child = children.find_by_slug($1) if slug_child found = slug_child.find_by_path(path, can_view_drafts, clean) return found if found end children.each do |child| found = child.find_by_path(path, can_view_drafts, clean) return found if found end end unless slug_child file_not_found_types = ([FileNotFoundPage] + FileNotFoundPage.descendants) file_not_found_names = file_not_found_types.collect { |x| x.name } condition = (['class_name = ?'] * file_not_found_names.length).join(' or ') condition = "status_id = #{Status[:published].id} and (#{condition})" unless can_view_drafts return children.where([condition] + file_not_found_names).first end slug_child end