Hi, <% source.strains.each_with_index do |strain, j| %> <% if (j == (source.strains.size - 1)) %> <font size="3">Strain <%= strain[0].appendix %> </font> <% end %> <% end %> I need to get output as If j value is last one of a loop, then i need to print first value of loop (j[0]). Kindly suggest me or correct above script. -- With Regards and Thanks, Palani Kannan. K, -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 October 2010 11:13, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > <% source.strains.each_with_index do |strain, j| %> > <% if (j == (source.strains.size - 1)) %> > <font size="3">Strain <%= strain[0].appendix %> </font> > <% end %> > <% end %> > > I need to get output as > > If j value is last one of a loop, then i need to print first value of loop > (j[0]). Kindly suggest me or correct above script.Do you realise you are doing nothing at all with all the other members of the array? If that is what you want then why bother to iterate through the array, just display element 0. Not related to your question but it is better to use css rather than inline font tags. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Dear Collin, On 20 October 2010 13:10, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 20 October 2010 11:13, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > Do you realise you are doing nothing at all with all the other members > of the array? If that is what you want then why bother to iterate > through the array, just display element 0. >Thank you for your point out.> > Not related to your question but it is better to use css rather than > inline font tags. >Its working with "source.strains[0].appendix". Thank you for helping out to find the issue.> > Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- With Regards, Palani Kannan. K, -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 October 2010 13:24, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear Collin, > > On 20 October 2010 13:10, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 20 October 2010 11:13, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hi, >> >> Do you realise you are doing nothing at all with all the other members >> of the array? If that is what you want then why bother to iterate >> through the array, just display element 0. > > Thank you for your point out. >> >> Not related to your question but it is better to use css rather than >> inline font tags. > > Its working with "source.strains[0].appendix". Thank you for helping out to > find the issue.Don''t forget to check for the case where the array is empty (so strains[0] will be nil) unless it is impossible for the array to be empty. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Dear Collin> Don''t forget to check for the case where the array is empty (so > strains[0] will be nil) unless it is impossible for the array to be > empty. >Ya... I got it. Loads of Thanks once again.> > Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- With Regards, Palani Kannan. K, Doctoral Researcher, Microbiology Department, German Collection Center for Microorganisms and Cell Cultures, Helmholtz-HZI Infectious diseases Research Campus, 38124, Braunschweig, Germany. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.