Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug silent database errors (such as "save") in Rails?

How can I get further information on errors that occur silently in Rails, such as @object.save?

like image 758
user456584 Avatar asked Oct 09 '12 22:10

user456584


2 Answers

Add bang so that an error is raised when validation fails.

@article.save!
# ActiveRecord::RecordInvalid: Validation failed: Title can't be blank...

Always use this method in preference to save if you don't expect validation to fail.

like image 188
Simon Perepelitsa Avatar answered Sep 28 '22 07:09

Simon Perepelitsa


As per this post, something like the following works:

logger.debug @item.errors.full_messages
like image 26
user456584 Avatar answered Sep 28 '22 07:09

user456584