Topic: What is a better way for checking any object is either nil?

I am not understanding how we are check any object for nil?
what is better solution to avoid nil error in rails

Re: What is a better way for checking any object is either nil?

This would be one approach.

  <%= object.name unless object.nil? %>

Re: What is a better way for checking any object is either nil?

but it not work for empty i want check for both nil also and empty('') also
there is wat like blank but it sometimes fail

Re: What is a better way for checking any object is either nil?

Try blank? instead

<%= object.name unless object.blank? %>

Last edited by schlick (2008-09-26 09:10:41)

Re: What is a better way for checking any object is either nil?

schlick wrote:

Try blank? instead

<%= object.name unless object.blank? %>

Yeah blank is a Rails extenstion for ruby that checks for both .empty? and .nil?

If it fails you are probably using it in the room context or place.