Paul Nichols
2007-Jul-13 10:14 UTC
If number of records = zero, display ''no records found''
[I''ve no idea how this got into the ''test'' section so sorry for the duplicate!] I have a list of scripts, that when one is clicked on displays a new page with relating runs for that script. I would like to include an if/else statement so that when the number of runs for a script is zero, the resulting page displays ''no runs found''. The runs display uses a <% for run in @runs %> loop to display a rows of run details, immediately after which I have placed <% if (@runs.size =0) %> - however, the ''else'' part of the statement is still run even when no rows are found. What am I doing wrong? -- 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jul-13 11:38 UTC
Re: If number of records = zero, display ''no records found''
On Jul 13, 2007, at 6:14 AM, Paul Nichols wrote:> I have a list of scripts, that when one is clicked on displays a new > page with relating runs for that script. > > I would like to include an if/else statement so that when the > number of > runs for a script is zero, the resulting page displays ''no runs > found''. > > The runs display uses a <% for run in @runs %> loop to display a > rows of > run details, immediately after which I have placed <% if > (@runs.size => 0) %> - however, the ''else'' part of the statement is still run even > when > no rows are found. > > What am I doing wrong?Well, for starters, not showing enough of your code, but I''ll take a shot anyway. <% if @runs.blank? -%> <p>No rows found</p> <% else -%> <% for run in @runs -%> <%= row_for(run) %> <% end -%> <% end -%> Since .blank? works with nil, it avoids possible issues with nil.size == 0 (which is better expressed as @runs.empty? anyway). -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul Nichols
2007-Jul-25 13:33 UTC
Re: If number of records = zero, display ''no records found''
I''ve tried the ".blank?" addition and rails just seems to ignore it for some reason. Are the minuses in the -%> imperative btw? I''ve not seen them before. Either way, it doesn''t seem to be working so can you suggest a way to debug this to see where i''m going wrong? -- 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Jul-25 15:04 UTC
Re: If number of records = zero, display ''no records found''
On 7/25/07, Paul Nichols <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Either way, it doesn''t seem to be working so can you suggest a way to > debug this to see where i''m going wrong?Post your code. Otherwise, everyone''s just guessing. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jean Nibee
2007-Jul-25 16:00 UTC
Re: If number of records = zero, display ''no records found''
Paul Nichols wrote:> I''ve tried the ".blank?" addition and rails just seems to ignore it for > some reason. > > Are the minuses in the -%> imperative btw? I''ve not seen them before. > > Either way, it doesn''t seem to be working so can you suggest a way to > debug this to see where i''m going wrong?Your ''if'' needs to be outside the ''for loop''. Otherwise there is nothing to iterate and the if statement is never hit. Hope this helps. -- 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 -~----------~----~----~----~------~----~------~--~---
Jean Nibee
2007-Jul-25 16:01 UTC
Re: If number of records = zero, display ''no records found''
Jean Nibee wrote:> Paul Nichols wrote: >> I''ve tried the ".blank?" addition and rails just seems to ignore it for >> some reason. >> >> Are the minuses in the -%> imperative btw? I''ve not seen them before. >> >> Either way, it doesn''t seem to be working so can you suggest a way to >> debug this to see where i''m going wrong? > > Your ''if'' needs to be outside the ''for loop''. Otherwise there is nothing > to iterate and the if statement is never hit. > > Hope this helps.OH, and <%= -%>, the - part means to NOT put a linefeed after the value being displayed. -- 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 -~----------~----~----~----~------~----~------~--~---
Paul Nichols
2007-Jul-26 08:26 UTC
Re: If number of records = zero, display ''no records found''
Bob Showalter wrote:> On 7/25/07, Paul Nichols <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> Either way, it doesn''t seem to be working so can you suggest a way to >> debug this to see where i''m going wrong? > > Post your code. Otherwise, everyone''s just guessing.Jean''s first post identified the problem - thanks Jean :) -- 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 -~----------~----~----~----~------~----~------~--~---