routing error uninitialized constant API rails

overflow picture overflow · Oct 26, 2013 · Viewed 14.7k times · Source

I have referred this link

to create my own api but facing an routing error since this is the first time am using namespace.

This is the controller I have

class API::IndexController < ApplicationController
  def index
    @clients = Client.all
    respond_to do |format|
        format.json
    end
  end
end

my route has

  namespace :api do
    resources :index
  end

Here is my inflection.rb

ActiveSupport::Inflector.inflections(:en) do |inflect|
    inflect.acronym 'API'
end

Once i finish it I tried localhost:3000/api/index.json but throwing error as

    Routing Error
uninitialized constant API

Can anyone help.

Answer

Schorty picture Schorty · Apr 17, 2014

Even if this question is pretty old...

I had the same problem and my solution was to rename the api-folders (in app/controllers and app/views) from "API" (full caps) to "api" (all lower case)

Hope this helps