There are many ways to create altnerate colors rows in a table but I was wondering if their is a nice Rails or Ruby way of doing it? Any suggestions? :-) Your Friend, John -- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org http://www.kopanas.com http://www.cusec.net http://www.soen.info --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
cycle() http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M000518 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is the way I did it: <% counter = 0 %> <% @companies.each do |company| -%> <li class="<%= ((counter % 2) == 0) ? ''light'' : ''dark'' %>"> <% counter += 1 %> I am sure their is a better way though. I hope :-) On 11/22/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There are many ways to create altnerate colors rows in a table but I > was wondering if their is a nice Rails or Ruby way of doing it? Any > suggestions? :-) > > Your Friend, > > John > > -- > John Kopanas > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > http://www.kopanas.com > http://www.cusec.net > http://www.soen.info >-- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org http://www.kopanas.com http://www.cusec.net http://www.soen.info --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 22 Nov 2006, at 15:28, John Kopanas wrote:> There are many ways to create altnerate colors rows in a table but I > was wondering if their is a nice Rails or Ruby way of doing it? Any > suggestions? :-)http://rubyonrails.org/api/classes/ActionView/Helpers/ TextHelper.html#M000518 cycle(first_value, *values) Returns a Cycle object whose to_s value cycles through items of an array every time it is called. This can be used to alternate classes for table rows: <%- for item in @items do -%> <tr class="<%= cycle("even", "odd") %>"> ... use item ... </tr> <%- end -%> You can use named cycles to prevent clashes in nested loops. You‘ll have to reset the inner cycle, manually: <%- for item in @items do -%> <tr class="<%= cycle("even", "odd", :name => "row_class") <td> <%- for value in item.values do -%> <span style="color:''<%= cycle("red", "green", "blue" :name => "colors") %>''"> item </span> <%- end -%> <%- reset_cycle("colors") -%> </td> </tr> <%- end -%> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
look into the ''cycle'' method. you can cycle through a couple different colors or CSS styles. for example, in your partial or in your output loop for the table: <% css_class = cycle(''report_detail_row'', ''report_detail_row_alt'') -%> and then put that in your table/div output ed On 11/22/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > There are many ways to create altnerate colors rows in a table but I > was wondering if their is a nice Rails or Ruby way of doing it? Any > suggestions? :-) > > Your Friend, > > John > > -- > John Kopanas > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > http://www.kopanas.com > http://www.cusec.net > http://www.soen.info > > > >-- Ed Hickey Developer Litmus Media 816-533-0409 ehickey-A4HEbNdjHgMmlAP/+Wk3EA@public.gmane.org A Member of Think Partnership, Inc www.ThinkPartnership.com Amex ticker symbol: THK --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
John Kopanas wrote:> This is the way I did it: > > <% counter = 0 %> > <% @companies.each do |company| -%> > <li class="<%= ((counter % 2) == 0) ? ''light'' : ''dark'' %>"> > <% counter += 1 %> > > > I am sure their is a better way though. I hope :-)http://rubyonrails.org/api/classes/ActionView/Helpers/TextHelper.html#M000518 <% @companies.each do |company| -%> <li class="<%= cycle("light", "dark") %>"> Alan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
or you could write: <% @companies.each do |company| -%> <li class="<%= cycle([''light'',''dark'']) %>"> --jake Ed Hickey wrote:> look into the ''cycle'' method. you can cycle through a couple different > colors or CSS styles. for example, in your partial or in your output > loop> for the table: > > <% css_class = cycle(''report_detail_row'', ''report_detail_row_alt'') -%> > > and then put that in your table/div output > ed > > On 11/22/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> -- >> John Kopanas >> john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org >> >> http://www.kopanas.com >> http://www.cusec.net >> http://www.soen.info >> >> > >> > > > -- > Ed Hickey > Developer > Litmus Media > 816-533-0409 > ehickey-A4HEbNdjHgMmlAP/+Wk3EA@public.gmane.org > A Member of Think Partnership, Inc > www.ThinkPartnership.com > Amex ticker symbol: THK-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry, i think you need to just give it the list of strings and not an Array. So the following would be correct: <li class="<%= cycle(''light'',''dark'') %>"> --jake jake wrote:> or you could write: > <% @companies.each do |company| -%> > <li class="<%= cycle([''light'',''dark'']) %>"> > > > --jake > > > Ed Hickey wrote: >> look into the ''cycle'' method. you can cycle through a couple different >> colors or CSS styles. for example, in your partial or in your output >> loop > >> for the table: >> >> <% css_class = cycle(''report_detail_row'', ''report_detail_row_alt'') -%> >> >> and then put that in your table/div output >> ed >> >> On 11/22/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> -- >>> John Kopanas >>> john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org >>> >>> http://www.kopanas.com >>> http://www.cusec.net >>> http://www.soen.info >>>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jake wrote:> <li class="<%= cycle(''light'',''dark'') %>">Holy crap, that is awesome. I love stumbling onto these happy little nuggets that show how I have been doing things the hard way for a long time. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<% counter = 0 -%> <% @companies.each do |company| -%> <li class="Line<%= counter -%>"> <% counter = 1 - counter -%> On Wed, Nov 22, 2006 at 09:38:29AM -0500, John Kopanas wrote:> > This is the way I did it: > > <% counter = 0 %> > <% @companies.each do |company| -%> > <li class="<%= ((counter % 2) == 0) ? ''light'' : ''dark'' %>"> > <% counter += 1 %> > > > I am sure their is a better way though. I hope :-) > > On 11/22/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > There are many ways to create altnerate colors rows in a table but I > > was wondering if their is a nice Rails or Ruby way of doing it? Any > > suggestions? :-) > > > > Your Friend, > > > > John > > > > -- > > John Kopanas > > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > > > http://www.kopanas.com > > http://www.cusec.net > > http://www.soen.info > > > > > -- > John Kopanas > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > http://www.kopanas.com > http://www.cusec.net > http://www.soen.info > > > >-- John Oxley Systems Administrator Yo!Africa E-Mail: john at yoafrica.com Tel: +263 4 858404 "The original point and click interface, was a Smith and Wesson." --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jorge Bernal ''Koke''
2006-Nov-28 09:25 UTC
Re: Sweetest Way To Created Alternate Colored Rows
I usually do this with JS, since that way I don''t have to add extra classes to each row. addEvent(window, "load", zebratables_init); function zebratables_init() { var even = false; if (!document.getElementsByTagName) return; tbls = document.getElementsByTagName("table"); for (ti=0;ti<tbls.length;ti++) { thisTbl = tbls[ti]; if ((('' ''+thisTbl.className+'' '').indexOf("zebra") != -1) && (thisTbl.id)) { for (j=1;j<thisTbl.rows.length;j++) { thisTbl.rows[j].className even ? ''tr_even'' : ''tr_odd''; // flip from odd to even, or vice-versa even = ! even; } } } } 2006/11/28, John Oxley <john-JA4dDRuU84dWk0Htik3J/w@public.gmane.org>:> > <% counter = 0 -%> > <% @companies.each do |company| -%> > <li class="Line<%= counter -%>"> > <% counter = 1 - counter -%> > > On Wed, Nov 22, 2006 at 09:38:29AM -0500, John Kopanas wrote: > > > > This is the way I did it: > > > > <% counter = 0 %> > > <% @companies.each do |company| -%> > > <li class="<%= ((counter % 2) == 0) ? ''light'' : ''dark'' %>"> > > <% counter += 1 %> > > > > > > I am sure their is a better way though. I hope :-) > > > > On 11/22/06, John Kopanas <kopanas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > There are many ways to create altnerate colors rows in a table but I > > > was wondering if their is a nice Rails or Ruby way of doing it? Any > > > suggestions? :-) > > > > > > Your Friend, > > > > > > John > > > > > > -- > > > John Kopanas > > > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > > > > > http://www.kopanas.com > > > http://www.cusec.net > > > http://www.soen.info > > > > > > > > > -- > > John Kopanas > > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > > > http://www.kopanas.com > > http://www.cusec.net > > http://www.soen.info > > > > > > > > > -- > John Oxley > Systems Administrator > Yo!Africa > E-Mail: john at yoafrica.com > Tel: +263 4 858404 > "The original point and click interface, was a Smith and Wesson." > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
John Oxley wrote:> <% counter = 0 -%> > <% @companies.each do |company| -%>Untested warning: <% @companies.each_with_index do |company, idx| -%> <li class="Line<%= idx % 2 -%>"> ... -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Deirdre Saoirse Moen
2006-Nov-28 22:28 UTC
Re: Sweetest Way To Created Alternate Colored Rows
I don''t like cycle because I want NO class in the non-even rows. Why make it harder for the browser to render your table? <% @registrations.each_with_index do |registration, i| %> <% row_class = i%2 == 1 ? '''' : '' class="even"'' %> <tr<%= row_class %>> [...] </tr> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rimantas Liubertas
2006-Nov-29 16:10 UTC
Re: Sweetest Way To Created Alternate Colored Rows
> I don''t like cycle because I want NO class in the non-even rows. Why > make it harder for the browser to render your table? > > <% @registrations.each_with_index do |registration, i| %> > <% row_class = i%2 == 1 ? '''' : '' class="even"'' %> > <tr<%= row_class %>> > [...] > </tr> > <% end %>Now let''s try the same with cycle: <% @registrations.each do |registration| %> <tr <%= cycle('''', ''class="even"'') -%>> [...] </tr> <% end %> Regards, Rimantas -- http://rimantas.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I also do this with Javascript instead. On 11/29/06, Rimantas Liubertas <rimantas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > I don''t like cycle because I want NO class in the non-even rows. Why > > make it harder for the browser to render your table? > > > > <% @registrations.each_with_index do |registration, i| %> > > <% row_class = i%2 == 1 ? '''' : '' class="even"'' %> > > <tr<%= row_class %>> > > [...] > > </tr> > > <% end %> > > Now let''s try the same with cycle: > > <% @registrations.each do |registration| %> > <tr <%= cycle('''', ''class="even"'') -%>> > [...] > </tr> > <% end %> > > > Regards, > Rimantas > -- > http://rimantas.com/ > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---