422 Rails中的不可处理实体 [英] 422 Unprocessable Entity in rails

查看:179
本文介绍了422 Rails中的不可处理实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的ror网站中实现上传文件功能.该文件是通过div上的拖放操作上传的

I am trying to implement upload a file functionality in my ror website. The file is uploaded by drag and drop on a div

我可以使用

e.originalEvent.dataTransfer.files[0].name
e.originalEvent.dataTransfer.files[0].size

以及用于上传文件

upload(e.originalEvent.dataTransfer.files[0]);

function upload(myfile) {
        var fd = new FormData();
        fd.append("name", myfile.name);
        fd.append("fileToUpload", myfile);
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "upload_main_file");
        xhr.send(fd);
}

控制器代码为

  def upload_main_file
    render :text => params[:name]
  end

路线是

post 'upload_material/upload_main_file'

但作为响应,我收到 422无法处理的实体错误

but in response I get the 422 Unprocessable Entity error

出什么问题了

推荐答案

upload_main_file 函数的开头添加此行可解决问题

Adding this line at the start of upload_main_file function fixed the problem

skip_before_action :verify_authenticity_token

这篇关于422 Rails中的不可处理实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆