Glen
1
Is there a way to call Array::index in Rails???
This is what I want to do:
@photos.map do |value|
@photos.index(value)%5 == 0 ? (@sorted_photos[i += 1] ||= []) <<
value : (@sorted_photos[i] ||= []) << value
end
However Rails is hijacking the index method call and breaking.
Glen
2
It would appear you can’t call each_with_index from a controller
either. Is there any way to actually do this?
Glen
3
Quoting G. [email protected]:
@photos.index(value)%5 == 0 ? (@sorted_photos[i += 1] ||= []) <<
value : (@sorted_photos[i] ||= []) << value
end
However Rails is hijacking the index method call and breaking.
Array::each_index() works for me in a model. Are you sure of operator
precedence and grouping? Try fully parenthesizing the expressions.
Jeffrey
Glen
4
My fault. I was forgetting to set @sorted_photos ||= [].