Search code examples
ruby-on-railsrubyruby-on-rails-2

How I can check if an object is null in ruby on rails 2?


I want to check when my object @objectname is not equal to null to show the values of the @objectname else to show that no values found.

I tried this:

<% if (@objectname != null) then %>

but I'm getting an error.


Solution

  • it's nilin 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