Skip to content

Commit

Permalink
Ensures correct page is found when two pages have same slug.
Browse files Browse the repository at this point in the history
The first page found (with a non-blank slug) in find_by_path should be a root page.
  • Loading branch information
nicholassm committed Apr 10, 2012
1 parent 5834331 commit 3d186b7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pages/app/models/refinery/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def live
# For example with about/example we would need to find 'about' and then its child
# called 'example' otherwise it may clash with another page called /example.
def find_by_path(path)
split_path = path.to_s.split('/')
page = ::Refinery::Page.by_slug(split_path.shift).first
split_path = path.to_s.split('/').reject(&:blank?)
page = ::Refinery::Page.by_slug(split_path.shift, :parent_id => nil).first
page = page.children.by_slug(split_path.shift).first until page.nil? || split_path.empty?

page
Expand Down Expand Up @@ -105,9 +105,9 @@ def by_title(title)
end

# Finds a page using its slug. See by_title
def by_slug(slug)
def by_slug(slug, conditions={})
locales = Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : ::I18n.locale
with_globalize(:locale => locales, :slug => slug)
with_globalize(conditions.reverse_merge(:locale => locales, :slug => slug))
end

# Shows all pages with :show_in_menu set to true, but it also
Expand Down

0 comments on commit 3d186b7

Please sign in to comment.