jquery - respond_to change response type -


I am calling the action of creating a controller through AJAX, when the object saves successfully, the JS response begins She goes. However, if the object fails to save due to validation, then I need a response to HTML. I hope to receive this by not returning the JS response to the More block (see the code given below), but it generates a 406 unacceptable error.

Any ideas about doing this?

I should also keep in mind why I want to do this, because I am not sure how to create a proper JS response when verification fails ...

thanks in advance !!! =]

Take Control Act

  Do not Answer. Format | If @ person.save flash [: notice] = 'successfully created.' Format.html {redirect_to (@person)} format.js else flash [: error] = 'new person' format.html {rendere: action = & gt; 'New'} end-end  

You are specifically requesting a js format in the URL You have to provide JS for your feedback. Instead of an option request, a format will not be specified, and then just the answer filter for xhr is similar to:

Do not answer. Format | If @ person.save flash [: notice] = 'successfully created.' If request.xhr? Format.js end format.html {redirect_to (@person)} and Flash [: Error] = 'A new person' format.html {rendere: action = & gt; This way, if you have a request without any format set, it will hit Js first, if it is an XHR request (ie, an AJAX request) However, if there is an error, then it will return HTML, no matter who it is.

Does this mean?


Comments