Rails

Using Each_with_index With Group_by In Rails

Posted by Weston Ganger on June 17, 2015

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
end


Related External Links:


Posted in Rails and Tagged with linux rails ruby 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts