How I can check if an object is null in ruby on rails 2?
it's nil
in Ruby, not null
. And it's enough to say if @objectname
to test whether it's not nil. And no then
. You can find more on if
syntax here:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures#if
You can check if an object is nil (null) by calling present? or blank? .
@object.present?
this will return false if the project is an empty string or nil .
or you can use
@object.blank?
this is the same as present? with a bang and you can use it if you don't like 'unless'. this will return true for an empty string or nil .