Forum: Ruby on Rails (no subject)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
thiago jackiw (Guest)
on 2006-01-16 20:53
(Received via mailing list)
Hello, I'm new to ruby on rails, migrating from php, and I have some
questions:

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?

2- How does the 'nil' object work?

Thanks
Jens A. (Guest)
on 2006-01-17 02:09
(Received via mailing list)
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_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.