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! ############### def create @product=Product.find_by_id(params[:product_id]) @variant=Variant.new(params[:variant]) @product.variants<<@variant @base_option=Option.new(:name=>params[:base_option][:name],:price=>0) @variant.options<<@base_option Variant.transaction do begin @variant.options.each{|option|option.save!} @variant.save! flash.now[:notice]=''variant created successfully'' render :action=>:create_variant,:layout=>false rescue Exception raise render :action=>:new_variant,:layout=>false end end end ############## Attachments: http://www.ruby-forum.com/attachment/4896/2.jpg -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hi can you help me? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 2, 4:12 am, Guo Yangguang <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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> > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > 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 > exceptionThanks 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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 2, 1:11 pm, Guo Yangguang <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you for your patience,fred. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.