[Rails] JSON response , error message
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
else
format.html { render action: "new" }
format.json { render json: @upload.errors, status:
:unprocessable_entity }
end
my validations:
validates_uniqueness_of :upload_file_name, :message => "File with
this name is already in the database"
validates :upload_file_size, :inclusion => {:in
=>10.megabytes..20.megabytes}, :message =>"Too big or too small"
def to_jq_upload
{
"name" => read_attribute(:upload_file_name),
"size" => read_attribute(:upload_file_size),
"url" => upload.url(:original),
"delete_url" => upload_path(self),
"delete_type" => "DELETE"
}
end
end
I have tried:
format.json { render json: => [{:error=> @upload.errors.full_messages }] }
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
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
Thanks in advanced
-- 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/tbZoal6I0UgJ.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home