Hi, I am beginner RoR. I need your advanced programming…
@rollresults = RollResult.where(:banker_id =>‘3’)
So you want to group your results by roll_no ?
Fred
Yes, I want to result group by roll_no.
@rollresults = RollResult.where(:banker_id =>‘3’) @rollresults.each do |p|
if p.roll_no == ‘512’ #<— Can’t work
# group by 3times…
else
# continues finding roll_no == ‘512’
end
end
I don’t understand what you mean by ‘group by 3 times’, but you might
want to look at group_by (method on array) or at sql’s “group by”
clause
Fred
Emm… ok, I just want to look the loop.
In the beginning, we searching the roll_no is equal to ‘512’.
Next collecting 3 steps, roll_no = [332, 512, 512], to output.
After that, we searching the roll_no also equal to ‘512’.
Next collecting 3steps again, roll_no = [264, 332, 666], to output.
Repeat the same method to find roll_no == ‘512’, next collect 3steps and
show them to output.
Can you make it? Thank you.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.