Hello
I am trying to show the errors that can occur by uploading a file (file
name, size).
I need have your error messages associated to the ‘error’ key in my json
response
I have tried:
format.json { render json: => [{:error=> @upload.errors.full_messages }]
}
using this shows the validation message but I need the status: to be
there
as well
render json: {error: @upload.errors.full_messages}, status:
:unprocessable_entity
shows no error messages at all
render json: {error: @upload.errors.full_messages}, status:
:unprocessable_entity
I get an error-text : Internal Server Error and not what stands in my
validation messages
Why are you sending a 422? If you really want to stick in the 400
range it would be more suitable to send a 409 conflict since it
literally is a conflict but some just prefer to stick to a generic
500.
The only js script i have there is the following and it is in the
index.html.erb. I am using this example for File uploader in Ruby on
Railshttps://github.com/tors/jquery-fileupload-rails-paperclip-example
.
Should I just add your code to mine or mine code has to be modified?
409 seems odd, given that the error could be “file too large” which
isn’t
really “a conflict with the current state of the resource” as described
in
the RFC.
Also note that returning a 422 causes ActiveResource to behave in an
expected manner (failing a save rather than raising an exception), which
may-or-may-not be relevant for this use case.
–Matt J.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.