代码之家  ›  专栏  ›  技术社区  ›  Darpan

rails在http调用中使用的错误方法上给出404而不是405

  •  0
  • Darpan  · 技术社区  · 6 年前

    我在Routes中有一个控制器动作-

    get '/landing' => 'main#landing_page', as: :my_landing_page
    

    因为这是一个get方法,所以我想处理这样的情况:一些用户点击了这个post请求(现在是post请求 /landing 给我404而不是 405 .

    请帮我修一下。我发现 this being filed as a bug ,他们说我要把它修好 resources ,但我不知道该在哪里修复。我是新来的。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Tony Vincent    6 年前

    在你 config/routes.rb

    post "/landing", to: "errors#method_not_allowed"

    app/controllers/errors_controller.rb

    class ErrorsController < ApplicationController
    
      def method_not_allowed
        head :not_found
      end
    
    end