Rails respond_to issue with json -


I am uploading some HTML5 and facing a problem that I can not figure out. Take this function code:

  If the image.save render: json = & gt; {: Condition = & gt; "Successfully uploaded image!"} And render: json = & gt; {: Condition = & gt; "Something went wrong with your upload!"} End   

This works and it does exactly what it should do. However, when I respond to the capture of HTML requests, it completely fails (though the HTML part works.)

  response_to do | Format | If @ image.save format.html {redirect_to (edit_product_path (@ image.product) ,: Notice = & gt; "Your image was successfully added.")} Format.json {Render: Status = & gt; "Successfully uploaded image!"} And format.html {redirect_to (edit_product_path (@ image.product) ,: Warning = & gt; "An error occurred while trying to upload your image. Please try again." }} Format.json {rendere: condition = & gt; "Something went wrong with your upload!"} End End   

Any ideas that might be wrong? I think I'm looking something simple thanks.

Edit - The problem has been solved

I thought it was a stupid thing that I had overlooked. Terminating the request was HTML, not HTML, which was due to the fact that after uploading the content type required to have multiple / form-data, response_to was to trigger the HTML.

The rider expects a status code so that it will not work

  format.json {render: status = & gt; "Something went wrong with your upload!"}   

You can call it

  format.json {rendere: error = & gt; "Something went wrong with your upload!",: Position => : Bad_request}    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -