Skip to content

Instantly share code, notes, and snippets.

@cassioscabral
Created January 14, 2015 13:25
Show Gist options
  • Save cassioscabral/431d804538d1c046ef05 to your computer and use it in GitHub Desktop.
Save cassioscabral/431d804538d1c046ef05 to your computer and use it in GitHub Desktop.
Getting all posts limited
@all_posts = []
@categories = Category.includes(:posts)
@categories.each do |category|
@all_posts.concat(category.posts.limit(3))
end
# precisando acessar uma category de um post == post.category
@all_posts.each do |post|
post.category
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment