使用 nginx、passenger 和 Rails 启用 DELETE 方法

Enable DELETE method with nginx, passenger and Rails

我尝试使用 passenger 和 nginx 部署 rails 应用程序。 一切正常,但是当我想发送 DELETE 请求时,例如:

<%= link_to "Sign out", sign_out_path, method: :delete %>

在开发中它工作正常但在使用 nginx 的生产中它正在做一个 GET 请求。所以逻辑上我得到这个错误:

ActionController::RoutingError (No route matches [GET] "/sign_out")

我读到 nginx 需要用 http_dav_module 编译才能使用 DELETE 方法。

我做到了,并像这样在 nginx 配置文件中添加了模块:

server {
  listen       8080;

  server_name  framework1.local.42.fr;
  passenger_enabled   on;

  location / {

    root          /rails/Framework00/public
    dav_methods   PUT DELETE;
    dav_access    group:rw  all:r;
  }

但我得到同样的结果,DELETE 方法不起作用。

知道如何解决这个问题吗?

发生这种情况是因为您在生产中遇到了 js 错误。 JavaScript 应该发送 DELETE 请求不工作。