Question

I' following the Ruby on Rails Tutorial. After I created an user, i destroyed it with destroy method, then i use find to check if it still exist, my console return exactly like the tutorial, but with some errors.
This is error image: enter image description here

Here i created a user called "abc" with id: 7, then i destroyed and use User.find(7) to find user.

I installed rails with rvm and created gemset named 1.9.3@rails3tutorial2endEd. I searched but don't know what this is problem, can anybody help? Thanks so much.

Was it helpful?

Solution

That's normal. Since the record does not exist anymore, you would get ActiveRecord::RecordNotFound

If you wanted to return nil instead. You could try something like

User.where(:id => 51).exists?

which will return true or false.

OTHER TIPS

Destroyed users cannot be found, since they no longer exist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top