我得到当我试图做一个条件,总结我的另一列错误总和控制器问题
@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"
我的控制器中的代码应该可以工作,但我不知道发生了什么
有人可以帮助我吗?我会很感激所有帮助
那么我在我的最后一个例子中使用了这个,并使用了相同的sintaxis,但我不知道这里发生了什么 –
这对我有用@ dolars = Policy.find(:all,:conditions =>“mount_type ='0 ““)的.sum(:安装)。 但不工作我的条件,我贴 –
感谢的人,但我做到了:d –