[Rails] error using find() method "couldn't find"

Jean-François jf.web3 at gmail.com
Tue Apr 11 09:13:48 GMT 2006


Hello Steven,

> I get the following error-message:
> "Couldn't find Activitycategory with ID=1"
>
> How do I make RoR handle this error?
> When the id is nog found he should return a string or 0 or whatever.
>
> I'm guessing by using exceptions but I'm not very familiar with ruby
> itself ...

Yes, you have to catch the exception raised by the #find method :

begin
  Activitycategory.find(1)
rescue RecordNotFound
  # handle the error
  # wish a flash[] message or whatever...
end

    -- Jean-François.

--
À la renverse.


More information about the Rails mailing list