@post.comments.limit(10).each do |comment| comment.description endBut in practical, sometimes we face that we have an array of objects fetched from DB and we want to access first or last few objects. Using following code we can easily solve it.
Reading first 10 records -
@posts.first(10).each do |post| post.title endReading last 10 records -
@posts.last(10).each do |post| post.title end
No comments:
Post a Comment