Follow Along as I Stumble on the Path to Learning RoR

Limiting the .each Results

On one of my views I pull in results to display, but I needed a way to figure out how to limit the results.

For example:

@posts.each do |post|

This Stack Overflow question helped me find the answer:
http://stackoverflow.com/questions/5624548/limit-each-list-in-rails

I ended up doing this to limit the display to 8:

@posts.take(8).each do |post|

Advertisements

Comments are closed.