[Rails] JSON request, show error message
Hello
I am trying to show the errors that can occur by uploading a file (file
name, size).
I tried to modify this code cut-off but I could not.
else
format.html { render action: "new" }
format.json { render json: @upload.errors, status:
:unprocessable_entity }
end
I have following validations and I want json to write when an error
occured, so something like this:
else
format.html { render action: "new" }
format.json { render json: @upload.errors, status:
:unprocessable_entity, error:"Error!" }
end
(it doenst work) and I need a specification of an error, that is written
in a validation :message
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
Thanks in advanced
--
Posted via http://www.ruby-forum.com/.
--
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.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home