[Rails] (no subject)

Jens Alfke jens at mooseyard.com
Mon Jan 16 21:26:55 GMT 2006


On 16 Jan '06, at 10:56 AM, thiago jackiw wrote:

> 1- How do I work with null objects without returning the rails  
> error to the user? Like if I'm searching for a record and no  
> record's found, how would I deliver my custom message to the user?

You could use the :all version of ActiveRecord#find, instead of just  
passing in the record id — that will return an empty array if no  
record is found, instead of throwing an exception.

> 2- How does the 'nil' object work?

It's a bit fancier than a simple nil/null pointer in most other  
languages. It is a real object: the sole instance of a class called  
NilClass, which you can look up in the core library ref. This class  
does pretty much nothing except respond to some boolean and type- 
conversion methods and the very useful 'nil?'.

But for the most part you can treat it just as you would a nil/null  
pointer in PHP or Java or C++ or whatever.

--Jens


More information about the Rails mailing list