Post returns 405 method not allowed

前端 未结 3 1836
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-19 02:01

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

3条回答
  •  面向向阳花
    2021-02-19 02:35

    In the ruotes.rb file, include your routes in a namespace, so it should look like this:

    Rails.application.routes.draw do
      namespace 'api' do
        Your routes here
      end
    end
    

    Then, add controllers corresponding to these routs in a folder with the same name of that namespace, so the app directory should look like this:

    app
    |  controllers
    |  |  api
    |  |  |  Your controller files here
    

    Finally, the controllers should be inside a module with the same name of the namespace but with the first letter capital, so each controller should look like this:

      module Api
        Your controller code here
      end
    

    Note: You can give each related set of routes/controllers different namespaces/modules. Also, you can use nested namespaces/modules.

提交回复
热议问题