4

I need to add an API endpoint to a Rails (5.0.2) app so I have created a TransitController under app/controllers/api.

The controller, for now, looks like

module Api   
  class TransitController < ActionController::Api
    def create 
      respond_to do |format|
        format.json { render :status => :ok, :nothing => true }
      end
    end
  end
end

I have updated my routes as follows

  namespace :api do
    post 'transits', to: 'transits#create'
  end

But now, when I try to hit the endpoint via curl I get

ActionController::RoutingError (uninitialized constant ActionController::Api)

In Rails 5+, shouldn't ActionController::Api be available by default?

Am I missing anything here?

Thanks

Sig
  • 5,476
  • 10
  • 49
  • 89
  • Possible duplicate of [ActionController::RoutingError: uninitialized constant Api::V1::ApiController](http://stackoverflow.com/questions/40039279/actioncontrollerroutingerror-uninitialized-constant-apiv1apicontroller) – Kick Buttowski May 17 '17 at 03:08

1 Answers1

6

Yes, it is available, but you need to use API instead of Api.

So change this:

class TransitController < ActionController::Api

to:

class TransitController < ActionController::API

More information here.

Gerry
  • 10,337
  • 3
  • 31
  • 40