Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我的rails型号赢得';为什么不能正确排序条目?_Ruby On Rails_Ruby On Rails 3_Scope - Fatal编程技术网

Ruby on rails 我的rails型号赢得';为什么不能正确排序条目?

Ruby on rails 我的rails型号赢得';为什么不能正确排序条目?,ruby-on-rails,ruby-on-rails-3,scope,Ruby On Rails,Ruby On Rails 3,Scope,我有一个rails模型,其作用域如下: default_scope order('created_at ASC') scope :published, order('created_at DESC').where(:draft=>false) 不幸的是,发布的作用域不会按降序排列条目 我写这个范围是不是写错了?我相信:published范围不会覆盖默认排序,除非您使用重新排序: 试一试 您的默认作用域仍将激活;您可以.reorder,显式获取Foo.unscoped.publish

我有一个rails模型,其作用域如下:

 default_scope order('created_at ASC')
 scope :published, order('created_at DESC').where(:draft=>false)
不幸的是,发布的作用域不会按降序排列条目


我写这个范围是不是写错了?

我相信
:published
范围不会覆盖默认排序,除非您使用
重新排序

试一试


您的默认作用域仍将激活;您可以
.reorder
,显式获取
Foo.unscoped.published
,或者使用

有关更多详细信息,请参阅,包括另一个SO问题和更多信息

scope :published, where(:draft=>false).reorder('created_at DESC')