Tip: Use Rails `cycle` to avoid `i % 2 == 0` in your view loops

11-Feb-2021 2175

Sometimes you need to keep track of how many times you’ve looped when rendering some views, for instance to alternate background colors to create a “striped”.Sometimes you need to keep track of how many times you’ve looped when rendering some views, for instance to alternate background colors to create a “striped” table.

Free eBook download

Download all our eBooks for free from Gumroad!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these books offer thousands of essential questions and answers across multiple languages. Download the complete collection for free from our Gumroad page. Free Ultimate Job Interview Preparation eBook collection