why does using sum in a rails 3.1 scope result in an error?
I have this scope:
scope :total_quantity, sum('quantity')
When I run:
MyModel.total_quantity
I get this error:
NoMethodError: undefined method `default_scoped?' for 4:Fixnum
Runnin开发者_开发百科g the sum method directly works
MyModel.sum('quantity') # 4
I can't find any documentation on the default_scoped? method, or why it is being called here. Do you know if there is a way to fix this problem?
Just try method instead of scope . It works like charm i also faced a same problem , but when i changed my scope to method its works fine . Below is working and tested code :)
def self.total_quantity
sum('quantity')
end
Let me know if it works or not ! Thanks
This worked for me
def self.total_quantity
sum('quantity')
end
But I did not get reason for an error if I uses scope instead of method.
精彩评论