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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to