开发者

Rails 3.1 broke sorting for MySql::Time

I just upgrading from Rails 3 to 3.1, and am getting this error:

NoMethodError (undefined method `<=>' for #<Mysql::Time:2011-01-12 00:00:00>):

on this line:

payments = Pay开发者_C百科ment.all( :select => 'date(created_at) as day, amount', :order => 'created_at',
:conditions => ["status = ?"], 1)
payments.group_by(&:day).sort

Any ideas how to fix?


You could try to explicitly cast the rows to ruby Time objects:

payments.group_by(&:day).sort{ |x,y| Time.parse(x) <=> Time.parse(y) }


Fixed it. I switched to the mysql2 gem (https://github.com/brianmario/mysql2), and that resolved the issue while keeping performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜