Each_with_index desired column output

Hi,

<% source.strains.each_with_index do |strain, j| %>
<% if (j == (source.strains.size - 1)) %>
Strain <%= strain[0].appendix %>
<% 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,

On 20 October 2010 11:13, PalaniKannan K [email protected]
wrote:

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

Dear Collin,

On 20 October 2010 13:10, Colin L. [email protected] wrote:

On 20 October 2010 11:13, PalaniKannan K [email protected] 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.

For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


With Regards,

Palani Kannan. K,

On 20 October 2010 13:24, PalaniKannan K [email protected]
wrote:

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

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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs