While creating 开发者_如何学Pythona new object i am getting ActiveRecord::RecordNotSaved error on before_save.
But i want to fetch the proper message other than ActiveRecord::RecordNotSaved error message.
How may i fetch the proper error message and pass it to the rescue?
begin
#some logic
raise unless object.save!
rescue ActiveRecord::RecordNotSaved => e
# How may fetch proper message where my object is failing here ..
# like object.errors.message or something like that.
end
begin
#some logic
@object.save!
rescue ActiveRecord::RecordNotSaved => e
@object.errors.full_messages
end
Why raise the exception and not just check if save or not ?
unless object.save
object.errors
end
精彩评论