I use will_paginate to get results: @results = Users.paginate(:all, :conditions => "... But how can I get a number of reults? -- 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 -~----------~----~----~----~------~----~------~--~---
How can I write it simple? if @results.empty? x = 0 else x = 1 end -- 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 -~----------~----~----~----~------~----~------~--~---
x = @results.empty? ? 1 : 0 -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of James Bond Sent: Tuesday, January 13, 2009 11:42 AM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: Number of entries How can I write it simple? if @results.empty? x = 0 else x = 1 end -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And instead of empty, you should use "blank?", that would work even if @results is "nil" x = @results.blank? ? 1 : 0 - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Tue, Jan 13, 2009 at 6:05 PM, Pardee, Roy <pardee.r-go57ItdSaco@public.gmane.org> wrote:> > x = @results.empty? ? 1 : 0 > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of James Bond > Sent: Tuesday, January 13, 2009 11:42 AM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Number of entries > > > How can I write it simple? > > if @results.empty? > x = 0 > else > x = 1 > end > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@results should never be nil unless he''s forgotten to define the variable which would just be Bad Programming. ----- Ryan Bigg Freelancer http://frozenplague.net On 14/01/2009, at 9:33 AM, Maurício Linhares wrote:> > And instead of empty, you should use "blank?", that would work even if > @results is "nil" > > x = @results.blank? ? 1 : 0 > > - > Maurício Linhares > http://alinhavado.wordpress.com/ (pt-br) | http:// > blog.codevader.com/ (en) > > > > On Tue, Jan 13, 2009 at 6:05 PM, Pardee, Roy <pardee.r-go57ItdSaco@public.gmane.org> wrote: >> >> x = @results.empty? ? 1 : 0 >> >> -----Original Message----- >> From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com >> ] On Behalf Of James Bond >> Sent: Tuesday, January 13, 2009 11:42 AM >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> Subject: [Rails] Re: Number of entries >> >> >> How can I write it simple? >> >> if @results.empty? >> x = 0 >> else >> x = 1 >> end >> -- >> 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Bond wrote:> I use will_paginate to get results: > > @results = Users.paginate(:all, :conditions => "... > > But how can I get a number of reults?to get a number of result you can get it by : @results.size if @results.size < 1 flash[:notice] = "There''s no result so its data is empty." end - Ruby Servant - [Some times i am terrorist of it] -- 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 -~----------~----~----~----~------~----~------~--~---
On Wed, Jan 14, 2009 at 3:24 AM, Rails Terrorist < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > James Bond wrote: > > I use will_paginate to get results: > > > > @results = Users.paginate(:all, :conditions => "... > > > > But how can I get a number of reults? > > to get a number of result you can get it by : > > @results.size > > if @results.size < 1 > flash[:notice] = "There''s no result so its data is empty." > end > > > - Ruby Servant - > [Some times i am terrorist of it] > -- > Posted via http://www.ruby-forum.com/. > > > >@results.size will give you the number in that ''page'' @results.total_entries will give you the total number of results you''re paginating over -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---