Skip to content

Commit

Permalink
Use presence of #to_str in FriendlyId::NonSluggableClassMethods to di…
Browse files Browse the repository at this point in the history
…fferentiate between incoming ids and friendly ids. This allows for duck-typing goodness.
  • Loading branch information
Empact committed Dec 5, 2009
1 parent f3f3cc8 commit 4f9ff06
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/friendly_id/non_sluggable_class_methods.rb
Expand Up @@ -5,7 +5,7 @@ module FriendlyId::NonSluggableClassMethods
protected

def find_one(id, options) #:nodoc:#
if id.is_a?(String) && result = send("find_by_#{ friendly_id_options[:method] }", id, options)
if id.respond_to?(:to_str) && result = send("find_by_#{ friendly_id_options[:method] }", id.to_str, options)
result.send(:found_using_friendly_id=, true)
else
result = super id, options
Expand All @@ -15,7 +15,7 @@ def find_one(id, options) #:nodoc:#

def find_some(ids_and_names, options) #:nodoc:#

names, ids = ids_and_names.partition {|id_or_name| id_or_name.is_a?(String) }
names, ids = ids_and_names.partition {|id_or_name| id_or_name.respond_to?(:to_str) && id_or_name.to_str }
results = with_scope :find => options do
find :all, :conditions => ["#{quoted_table_name}.#{primary_key} IN (?) OR #{friendly_id_options[:method]} IN (?)",
ids, names]
Expand Down

0 comments on commit 4f9ff06

Please sign in to comment.