【发布时间】:2014-06-09 20:57:30
【问题描述】:
我有我的范围:
scope :latest_photos, -> {order(:created_at).reverse_order.limit(10)}
应该把最新的照片放在第一位吧?好吧,照片会放在最后一个位置。
我也试过了:
scope :latest_photos, -> {order('created_at DESC').limit(10)}
但什么都没有。有任何想法吗?谢谢!
编辑
这里出了点问题:
routes.rb
get 'spots/ultimos' => 'photos#latest
照片控制器
def latest
@categories = Category.all
@zones = Zone.all
@photos = Photo.latest_photos
@action = 'general'
@photos = Photo.paginate(:page => params[:page])
render :index
end
型号
scope :latest_photos, -> {order(created_at: :desc).limit(10)}
【问题讨论】:
-
Photo.latests_photos.to_sql有什么用?
标签: ruby-on-rails ruby scopes