Validation messages and $.parseJSON(xhr.responseText).errors

43 views
Skip to first unread message

Akvarel

unread,
Oct 29, 2012, 3:59:26 PM10/29/12
to rubyonra...@googlegroups.com
Hello!

I try to catch a validation message with a `$.parseJSON(xhr.responseText).errors` but an alert message hows me "undefined"  and I do not understand why.

hier are my validations:
 

    validates :upload_file_name,  :presence   => true,
                                    :format     =>{:with => %r{\.(jpg)$}i,:message =>"It should be a pdf File"}
                                   
      validates_uniqueness_of :upload_file_name, :message => "blabla"
    
      validates :upload_file_size,  :inclusion  => {:in =>1.megabytes..20.megabytes,:message=>"bla"}

json:
 

    format.json{ render json: {error: @upload.errors.full_messages}, :status =>422}

and javascript for that:

     $('#fileupload').fileupload({      
   
   
            error: function(xhr){
              var errors = $.parseJSON(xhr.responseText).errors
              alert(errors)        
            }
                  });

Thanks in advanced
 
Reply all
Reply to author
Forward
0 new messages