ruby on rails - Loop through each element from third to last of active record object -
i have active record object of array.
@obj = user.post
now want loop through @obj third element last. want below
@obj.third-to-last.each #output here end
i can using counter , if else condition. want know if there better , simple way this.
use array#drop
method drop first 2 elements of @obj
:
@obj.drop(2).each |obj| # whatever... end
Comments
Post a Comment