handle exception in ajax call

sorry to bother to help me again.I invoke create action using ajax.The variant and it's associations are put in a transaction.When both are saved successfully,render create_variant using ajax.When anyone unsuccessfully,rallback all the saving manipulation,rescue exception,and render the new_variant using ajax,which has <%=error_messages_for :variant-%> to display invalidations. But when inputtings are invalid,i always get something like attachment.It seems the exception is not handled at all,the error meassages are not displayed as expected.can you help me? thank!

hi   can you help me?

I tested using non-ajax call,but the problem was same,the exception was not handled like the attachment and new_variant template was not rendered as expected.The render should not be used in the rescue block? can you help me?

I tested using non-ajax call,but the problem was same,the exception was not handled like the attachment and new_variant template was not rendered as expected.The render should not be used in the rescue block? can you help me?

You're rescuing the exception but then you're re-raising it so your render call never happens. Also a more usual way is to call save and test the return value of that rather than call save! and rescue the exception

Fred

You're rescuing the exception but then you're re-raising it so your render call never happens. Also a more usual way is to call save and test the return value of that rather than call save! and rescue the exception

Thanks fred.But i want transaction(which need save!) to let them all either to be saved or not.If i rescue the exception and not re-raising it,is it right to handle exception in this way?

> You're rescuing the exception but then you're re-raising it so your > render call never happens. Also a more usual way is to call save and > test the return value of that rather than call save! and rescue the > exception

Thanks fred.But i want transaction(which need save!) to let them all either to be saved or not.If i rescue the exception and not re-raising it,is it right to handle exception in this way?

in that case you should rescue the exception outside of the transaction

Fred

Thank you for your patience,fred.