简体   繁体   English

使用Remotipart上载Ajax文件进行开发,heroku上开发406

[英]Ajax file upload with Remotipart works on development, 406 on heroku

I have a series of remote forms on a page, each of which should be able to upload a file when the object is updated or created. 我在页面上有一系列远程表单,当对象被更新或创建时,每个远程表单都应该能够上传文件。 I've checked and tested thoroughly in development, and as long as I'm using Remotipart this seems to work just fine. 我已经在开发中进行了彻底的检查和测试,并且只要使用Remotipart,它就可以正常工作。

However, this morning I pushed my changes up to my staging server on Heroku, and when I try to submit one of these forms with a file upload, I get a 406 Not Acceptable response from the server. 但是,今天早上,我将所做的更改推送到了Heroku上的登台服务器上,当我尝试使用文件上传提交这些表单之一时,从服务器收到406 Not Acceptable响应。 So here my page does not get updated because I don't get my expected js template response from the server. 所以在这里我的页面没有更新,因为我没有从服务器得到预期的js模板响应。 However, if I reload the page, the file I tried to upload shows up just fine. 但是,如果我重新加载页面,则尝试上传的文件显示就很好。

The forms are created using simple_form (with remote: true ) and I'm using Carrierwave with Fog to upload the files to S3 (also tested in development, so I don't think it's that). 表单是使用simple_form创建的(带有remote: true ),并且我正在使用带有Fog的Carrierwave将文件上传到S3(也在开发中进行了测试,所以我认为不是这样)。

The network inspector shows the same kind of data as far as I can tell. 据我所知,网络检查器会显示相同类型的数据。 I see no significant differences in the request payload. 我发现请求有效负载没有明显差异。

I don't know what I'm doing wrong (if anything). 我不知道自己在做什么错(如果有的话)。 Has anyone else experienced this or perhaps have an idea what's wrong? 有没有其他人经历过这种情况,或者有一个想法出了什么问题?

Update 更新资料

So I've figured at least one thing out. 因此,我至少知道了一件事情。 My controller was only handling js format requests. 我的控制器仅处理js格式的请求。 I handled html formatted requests by redirecting to another path, and the html of that page is now sent back as the ajax response. 我通过重定向到另一个路径来处理html格式的请求,并且该页面的html现在作为ajax响应发送回了。 What I can't seem to figure out is why, when the content types and everything seem to be the same on both development and staging, do the responses get sent/rendered in the wrong format. 我似乎无法弄清楚的是,为什么在开发和登台的内容类型和所有内容都相同的情况下,响应会以错误的格式发送/呈现。

Welp, I solved it. 威尔,我解决了。 Turns out the javascript was getting included, but none of the middleware. 原来JavaScript已被包含在内,但没有中间件。 On closer inspection, I found that a few of my gems were placed in the assets group in the Gemfile, which would get included on development environments, but not in production. 通过仔细检查,我发现我的一些宝石被放置在Gemfile中的assets组中,该组将包含在开发环境中,但未包含在生产中。

I moved remotipart out of the assets group and everything works fine now. 我将remotipart移出资产组,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM