blank?

written by Jan on August 20th, 2007 @ 04:41 PM

In Rails, when checking a value from params to see if it’s empty, don’t use


  params[:a_value].empty?

because if params[:a_value] isn’t given (nil), it will fail with a NoMethodError. Use this instead:


  params[:a_value].blank?

blank? is a Rails core-extension that lives in Object, so everything has the blank? method.



Comments are closed

Options:

Size