Home Rails 对于不合法的model,打印出详细的提示
Post
Cancel

Rails 对于不合法的model,打印出详细的提示

很多时候,我们会在项目中遇到 user.save! 的时候,报错(只给出exception )但是却没有详细的信息.

这个时候,就需要把遇到的错误打印出来了.而不是一个一个的去猜.

begin
    user.save!
rescue 
    puts user.errors.full_messages
end
This post is licensed under CC BY 4.0 by the author.