Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:31:08+00:00 2026-06-11T06:31:08+00:00

I’m trying to define a custom post action in a controller, but I’m having

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:31:10+00:00Added an answer on June 11, 2026 at 6:31 am

    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]"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.