Do you use statements like

 .. if !name.nil? && !name.empty?
 .. if params[:name] and !params[:name].empty?

in your code? Using the blank? function of Rails, they can be simplified to

 .. if !name.blank?
 .. if !params[:name].blank?

But we can go even further. Using the present? function, this is equal to

 .. if name.present?
 .. if params[:name].present?

See the documentation for the class object: an object is present if it‘s not blank. An object in Rails is blank if it‘s false, empty, or a whitespace string. That means “”, ” “, nil, [], and {} are blank.

About these ads