当我尝试做一个条件并对我的另一列求和时出现错误
@dolars =Policy.find(:all ,:conditions=>"type_money = '1' ").sum(&:amount_ensure)
我的桌子
Policies
|id| |type_money| |amount_ensure|
integer integer integer
我的日志显示这个
nil can't be coerced into Fixnum
.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:in `+'
.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.5/lib/active_support/core_ext/enumerable.rb:61:in `sum'
.rvm/gems/ruby-1.8.7-p370/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:211:in `inject'
.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.5/lib/active_support/core_ext/enumerable.rb:61:in `each'
.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.5/lib/active_support/core_ext/enumerable.rb:61:in `inject'
.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.5/lib/active_support/core_ext/enumerable.rb:61:in `sum'
.rvm/gems/ruby-1.8.7-p370/gems/activesupport-2.3.5/lib/active_support/core_ext/enumerable.rb:59:in `sum'
我正在尝试这样做:
SELECT id, SUM(amount_ensure) As dolars,type_money
FROM Policies
WHERE type_money= "1"
我的控制器中的代码应该可以工作,但我不知道发生了什么
有人可以帮助我吗?我将非常感谢所有帮助