Skip to content

Commit

Permalink
Fix friendly finds on Rails 4.2
Browse files Browse the repository at this point in the history
Rails has done its usual song and dance and changed the way Model.find
works in 4.2, so it's now no longer delegated to the internal relation
class, but is its own method, so we solve this by including the finders
module in the model class as well as the relation class.

Resolves #607
  • Loading branch information
norman committed Jan 16, 2015
1 parent 0c09801 commit 7025196
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/friendly_id/finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def relation_delegate_class(klass)
def self.setup(model_class)
model_class.instance_eval do
relation.class.send(:include, friendly_id_config.finder_methods)
if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
model_class.send(:extend, friendly_id_config.finder_methods)
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/friendly_id/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def self.setup(model_class)
friendly_id_config.finder_methods = FriendlyId::History::FinderMethods
if friendly_id_config.uses? :finders
relation.class.send(:include, friendly_id_config.finder_methods)
if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
model_class.send(:extend, friendly_id_config.finder_methods)
end
end
end
end
Expand Down

0 comments on commit 7025196

Please sign in to comment.