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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It would appear you can''t call each_with_index from a controller either. Is there any way to actually do this? On Aug 31, 11:20 pm, Glen <DamnBig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Quoting Glen <DamnBigMan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > It would appear you can''t call each_with_index from a controller > either. Is there any way to actually do this? > > On Aug 31, 11:20 pm, Glen <DamnBig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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.Array::each_index() works for me in a model. Are you sure of operator precedence and grouping? Try fully parenthesizing the expressions. Jeffrey --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
My fault. I was forgetting to set @sorted_photos ||= []. On Sep 1, 12:26 am, "Jeffrey L. Taylor" <r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:> Quoting Glen <DamnBig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > It would appear you can''t call each_with_index from a controller > > either. Is there any way to actually do this? > > > On Aug 31, 11:20 pm, Glen <DamnBig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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. > > Array::each_index() works for me in a model. Are you sure of operator > precedence and grouping? Try fully parenthesizing the expressions. > > Jeffrey--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---