Using Each_with_index With Group_by In Rails

Posted by Weston Ganger

I wanted to use each_with_index on my group_by but it wasnt working right.

Ruby just requires you to wrap some parameters in parenthesis

@posts.group_by(&:category).each_with_index do |(category, posts), index|
  # do work

Related External Links:

Article Topic:Software Development - Rails

Date:June 17, 2015

Recommended Posts



Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected