Chris Richards
2006-Oct-25 10:33 UTC
Is there a better way of doing this? checking for params
I always do this when checking to see if a parameter exists and that it is not blank: if params[:name] and !params[:name].empty? ... end Is there a better way? a simpler way. Thanks in advance Chris -- 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear
2006-Oct-25 11:34 UTC
Re: Is there a better way of doing this? checking for params
Chris Richards wrote:> I always do this when checking to see if a parameter exists and that it > is not blank: > > if params[:name] and !params[:name].empty? > ... > end > > Is there a better way? a simpler way.Rails defines an method ''blank?'' that will work for any object, including nil. It returns true when it''s called on a nil object, or an empty string, hash or array. So you can use if !params[:name].blank? Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---