Skip to content

Commit

Permalink
Fix not using longest possible association name first in traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
ernie committed Oct 14, 2011
1 parent 3f9fa1c commit 5d59346
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/ransack/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ def traverse(str, base = @base)
str ||= ''

if (segments = str.split(/_/)).size > 0
association_parts = []
remainder = []
found_assoc = nil
while !found_assoc && segments.size > 0 && association_parts << segments.shift do
while !found_assoc && segments.size > 0 do
# Strip the _of_Model_type text from the association name, but hold
# onto it in klass, for use as the next base
assoc, klass = unpolymorphize_association(association_parts.join('_'))
assoc, klass = unpolymorphize_association(segments.join('_'))
if found_assoc = get_association(assoc, base)
base = traverse(segments.join('_'), klass || found_assoc.klass)
base = traverse(remainder.join('_'), klass || found_assoc.klass)
end

remainder.unshift segments.pop
end
raise UntraversableAssociationError, "No association matches #{str}" unless found_assoc
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Ransack
VERSION = "0.5.7"
VERSION = "0.5.8"
end

0 comments on commit 5d59346

Please sign in to comment.