You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
singleton_class.send(:define_method, name) do |*args|
scope = all
scope = scope._exec_scope(*args, &body)
scope = scope.extending(extension) if extension
scope
end
Not the -> { where("amount > 0") } that I'd like.
Any ideas?
The text was updated successfully, but these errors were encountered:
this is because Rails generates a new method that will call your block only when the scope is called. method_source is properly returning the source of the generated method
I was able to get the source code of a scope by adding this:
ActiveRecord::Scoping::Named::ClassMethods.prepend(Module.new do
def scope(name, body, &block)
(@__named_scopes__ ||= {})[name] = body
super
end
end)
Note that if you run this code in the Rails console you would need to reload the model (with default config.cache_classes, use reload! for development and Object.send(:remove_const, :Transaction); load "./app/models/transaction.rb" for production).
I have a Rails scope:
But when I do:
I get:
Not the
-> { where("amount > 0") }
that I'd like.Any ideas?
The text was updated successfully, but these errors were encountered: