我正在尝试post在控制器中定义自定义操作,但我有一些问题。
这是我的控制器:
module Api
  module V1
    class ExamplesController < ApplicationController
      def create_a
        ...
      end
      def create_b
        ...
      end
    end
  end
end
我希望两个动作/方法都是post动作。这是我的路线文件中的内容:
namespace :api do
  namespace :v1 do
    match 'examples/create_a', :controller => 'examples', :action => 'create_a'
    match 'examples/create_b', :controller => 'examples', :action => 'create_b'
  end
end
我可以通过 t 请求达到这两种方法ge,但我想基于 http 触发它们post。此外,如果我通过rake routes它检查并不会告诉我它是否是 GET、PUT、POST 等方法。它只是空白。我如何告诉路线它应该是一种post方法?
浏览器中的post请求在我的方法中看起来如何?
url: http://localhost:3000/api/v1/examples/create_a.json/create_a
header: Content-Type: application/x-www-form-urlencoded
data: paramA=45¶mB¶mC
这是post对我的控制器操作执行的正确 URL 模式create_a吗?