aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/scoping
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-20 21:35:58 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-20 21:35:58 -0300
commit9a1abedcdeecd9464668695d4f9c1d55a2fd9332 (patch)
tree287c625ff80dc7feeddea2dcb5a59ce6783a9cd3 /activerecord/lib/active_record/scoping
parentc72d6c91a7c0c2dc81cc857a1d6db496e84e0065 (diff)
parent9c3afdc327132c7f1f4d05eebc0c05b715442e7d (diff)
downloadrails-9a1abedcdeecd9464668695d4f9c1d55a2fd9332.tar.gz
rails-9a1abedcdeecd9464668695d4f9c1d55a2fd9332.tar.bz2
rails-9a1abedcdeecd9464668695d4f9c1d55a2fd9332.zip
Merge pull request #14544 from jefflai2/named_scope_sti
Fixes Issue #13466. Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/scoping')
-rw-r--r--activerecord/lib/active_record/scoping/named.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb
index 49cadb66d0..826b710e92 100644
--- a/activerecord/lib/active_record/scoping/named.rb
+++ b/activerecord/lib/active_record/scoping/named.rb
@@ -148,9 +148,13 @@ module ActiveRecord
extension = Module.new(&block) if block
singleton_class.send(:define_method, name) do |*args|
- scope = all.scoping { body.call(*args) }
+ if body.respond_to?(:to_proc)
+ scope = all.scoping { instance_exec(*args, &body) }
+ else
+ # Body is given as an object instead of a block, so invoke call()
+ scope = all.scoping { body.call(*args) }
+ end
scope = scope.extending(extension) if extension
-
scope || all
end
end