过帐返回405方法不被允许 [英] Post returns 405 method not allowed

查看:147
本文介绍了过帐返回405方法不被允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails本地服务器出现问题,所有Post调用开始返回不允许的405方法. 但是,我们的登台服务器和生产服务器没有问题.它发生在所有代码分支上,甚至是尚未更新的代码.调试时,我看到它到达了路由文件,但未到达控制器.

我尝试删除我的gem并重新安装,从WEBrick切换到Pama,创建了git项目的新克隆.

服务器

Started POST "/assets" for ::1 at 2015-07-14 12:14:27 -0400

Chrome中的网络"标签

常规

Remote Address:[::1]:3000
Request URL:http://localhost:3000/assets
Request Method:POST
Status Code:405 Method Not Allowed

响应

HTTP/1.1 405 Method Not Allowed
Cache-Control:no-cache
Content-Length:18
Content-Type:text/plain
X-Request-Id:9b0b2dd2-065b-4610-91c9-36494ea95353
X-Runtime:0.145368

请求

POST /assets HTTP/1.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Cache-Control:no-cache
    Connection:keep-alive
    Content-Length:8376627
    Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryx8y8PBySdt7dxs4A
    Cookie:activeAccordionGroup=collapseTwo; _fusion360_hub_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWFlYmVlOGZjZmI3YzVlYjBjNjAyYzcyMzNhNzIyMzIwBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTllM2xhK1k4WG1hd2xYNnZCOEtHOEhPaHNTbWQvZGR2cGJ3bU9WUXIwRzg9BjsARg%3D%3D--4e108cb5f6eca3d986c0b3accec07bd2c27560b2; _mkto_trk=id:760-CWR-293&token:_mch-localhost-1435859445290-79614; _pk_id.845225.1fff=9847e7981c291a08.1435859445.1.1435859445.1435859445.; _allegorithmic-substance-marketplace_session=M3dMUCs4ZEtWSTFJTFVHV2VYN2pESFdHcGlHL2grVVVKSGxIWEZ3MlhXQkpRdHE2L0ZkMFpURmZDWGl6aTMxYSttMXFSQXN2M08zVVVXZTRHMDNKOHJOUzA1TmZoYnMwWURjb3c0Rkx6MTJYOW1Uem9aNGRObEMvc1NpSWo5VnQ4dUIzRnRtTFpnMlpOQVVZUU1SdWxiN1ZjN1lIMVd3Sk5jaXkyZkZLZ3duWTc4K2dnK0FSK29JVWdva2t0eUN1Q3hJbjFERHJVaGtndjVoWGxDRUlndz09LS1rZDdWcmtEWHlJWHRpZjc1MFNUSDF3PT0%3D--d34962721f449064dfdfd4629c0239ea1340aee4; __profilin=p%3Dt
    Host:localhost:3000
    Origin:http://localhost:3000
    Pragma:no-cache
    Referer:http://localhost:3000/assets/new
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36

解决方案

您有一条路线资产",这是Rails中的保留路线,并且是为Rails Asset Pipeline保留的.

如果必须使用资产"路线,则需要通过在 development.rb production.rb 中添加以下行来为Asset Pipeline提供另一个挂载点配置块:

config.assets.prefix = '/assetz'

然后重新启动服务器.

这样,您的所有资产都将安装在"/assetz"上,并且可以在"/assets"上使用POST请求.

祝您编程愉快!

参考:

1) StackOverflow

I am having an issue with my Rails localhost Server, all Post calls started returning 405 method not allowed. However there are no problems on our staging and production servers. It is happening on all branches of code even ones that have not been updated. When debugging I see that it reaches the routes file but not the controller.

I have tried removing my gems and reinstalling, switching from WEBrick to Pama, creating a new clone of my git project.

Server

Started POST "/assets" for ::1 at 2015-07-14 12:14:27 -0400

Network Tab in Chrome

General

Remote Address:[::1]:3000
Request URL:http://localhost:3000/assets
Request Method:POST
Status Code:405 Method Not Allowed

Response

HTTP/1.1 405 Method Not Allowed
Cache-Control:no-cache
Content-Length:18
Content-Type:text/plain
X-Request-Id:9b0b2dd2-065b-4610-91c9-36494ea95353
X-Runtime:0.145368

Request

POST /assets HTTP/1.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Cache-Control:no-cache
    Connection:keep-alive
    Content-Length:8376627
    Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryx8y8PBySdt7dxs4A
    Cookie:activeAccordionGroup=collapseTwo; _fusion360_hub_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWFlYmVlOGZjZmI3YzVlYjBjNjAyYzcyMzNhNzIyMzIwBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTllM2xhK1k4WG1hd2xYNnZCOEtHOEhPaHNTbWQvZGR2cGJ3bU9WUXIwRzg9BjsARg%3D%3D--4e108cb5f6eca3d986c0b3accec07bd2c27560b2; _mkto_trk=id:760-CWR-293&token:_mch-localhost-1435859445290-79614; _pk_id.845225.1fff=9847e7981c291a08.1435859445.1.1435859445.1435859445.; _allegorithmic-substance-marketplace_session=M3dMUCs4ZEtWSTFJTFVHV2VYN2pESFdHcGlHL2grVVVKSGxIWEZ3MlhXQkpRdHE2L0ZkMFpURmZDWGl6aTMxYSttMXFSQXN2M08zVVVXZTRHMDNKOHJOUzA1TmZoYnMwWURjb3c0Rkx6MTJYOW1Uem9aNGRObEMvc1NpSWo5VnQ4dUIzRnRtTFpnMlpOQVVZUU1SdWxiN1ZjN1lIMVd3Sk5jaXkyZkZLZ3duWTc4K2dnK0FSK29JVWdva2t0eUN1Q3hJbjFERHJVaGtndjVoWGxDRUlndz09LS1rZDdWcmtEWHlJWHRpZjc1MFNUSDF3PT0%3D--d34962721f449064dfdfd4629c0239ea1340aee4; __profilin=p%3Dt
    Host:localhost:3000
    Origin:http://localhost:3000
    Pragma:no-cache
    Referer:http://localhost:3000/assets/new
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36

解决方案

You have a route "assets", which is a reserved route in Rails and it is reserved for Rails Asset Pipeline.

If you must use the "assets" route then you need to give Asset Pipeline another mount point by adding the following line in your development.rb or production.rb configuration block:

config.assets.prefix = '/assetz'

And restart your server.

By this all your assets will be mounted on "/assetz" and you will be able to use POST requests on "/assets".

Happy coding!

Reference:

1) StackOverflow

这篇关于过帐返回405方法不被允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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