【发布时间】:2023-03-14 01:41:01
【问题描述】:
我有很多方法可以在特定活动记录之后查找记录。例子是:
def photo_recent
offsetphoto = Photo.find(params[:id])
@photos = Photo.recent.where('created_at> ?', offsetphoto.id).limit(10)#recent is a scope using created_at
end
def photo_recent
offsetphoto = Photo.find(params[:id])
@photos = Photo.popular.where('like_count > ?', offsetphoto.like_count).limit(10)#popular is a scope using like_count
end
我想知道是否有任何方法可以将其模块化,例如:
@photos = Photo.recent.offset(Photo.find(params[:id])).limit(10)
【问题讨论】:
标签: sql ruby-on-rails activerecord offset