Rails 3 - how to make own error handler -


Can someone help me, please, for example how to create your own error handle, for example, when I Trying to delete the item from the database that does not exist (delete the item with the id is not present)?

I tried to search on Google, but I still do not have anything that works.

I think you will never read it, but it can help others.

You have 3 ways to manage it.

You can catch the exception with the defense. But this is not the best way.

You can check that your ID is present, you have some ways to do this. (For example calculation). But this is not the best way, because you have 2 questions.

Or you can use find_by_id, it does not take exception, and when your object does not exist, then return zero. You only have to check about the result.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -