[英]how to respond_to a json request with only the 20 recents objects? (rails)
I wish to send to the client only the 20 recent Post objects. 我希望只向客户端发送最近的20个Post对象。
How do i that? 我怎么样? I'm new to rails so ill appreciate your advice very much. 我是铁杆新手,非常感谢你的建议。 thanks. 谢谢。
Just do: 做就是了:
@posts = Post.all(:order => 'created_at desc', :limit => 20)
respond_to do |format|
format.json
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.