Q:

How do I specify a custom POST action when using `match` in my `routes.rb` file?

I'm trying to define a custom post action in a controller, but I'm having some questions.
This is my controller:
module Api
  module V1
    class ExamplesController < ApplicationController
      def create_a
        ...
      end

      def create_b
        ...
      end
    end
  end
end

I want both actions/methods to be post actions. This is what I have in my routes file:
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

I can reach these two methods via get requests, but I'd like to trigger them based on an http post. Also, if I check via rake routes it does not tell me if it's a GET, PUT, POST, etc. method. It's just blank. How do I tell a route that it's supposed to be a post method?
And how would a post request in the browser look like to my method?
url: http://localhost:3000/api/v1/examples/create_a.json/create_a
header: Content-Type: application/x-www-form-urlencoded
data: paramA=45&paramB&paramC

Is this the proper URL pattern to do a post to my controller action create_a?

A:

Generally you use match when you want to map some kind of logical name to a RESTful route and/or to create an alias for a RESTful route. What you're doing with match is fine (in the sense that it will work), but you're just missing a small thing (which I'll so you later).
First, let's look at a typical use for match creating an alias for a route:
match "profile" => "users#show"

This route lets you use an application path of /profile to show a user instead of the path /users/:id.
Since your code isn't mapping one name to another, you don't need a match rule. Your use of match adds duplication to your code that isn't necessary, and using match in the case you presented is more verbose than necessary. Here's an example of how you could write your API routes without match, specifying that they are accessible via post only:
namespace :api do
  namespace :v1 do
    post "examples/create_a"
    post "examples/create_b"
  end
end

And here's an example with match, adding the :via parameter (which is what you're missing in your code example) to specify the HTTP verb:
namespace :api do
  namespace :v1 do
    match 'examples/create_a' => "examples#create_a", :via => :post
    match 'examples/create_b' => "examples#create_b", :via => :post
  end  #           ^ ---- DUPLICATION ---- ^
end

Note the duplication of code here. Since you're not mapping one path name to another you've typed your identically named paths twice when compared to the non-match version.
You'll also note that I took out the :controller and action parameters when compared to your original example code, as Rails will infer this automatically when you use the form:
"[controller]/[action]" => "[controller]#[action]"

