简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM