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

Chris R. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs