Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

routing error uninitialized constant API rails

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.

like image 303
Prabhakaran Avatar asked Oct 26 '13 11:10

Prabhakaran


1 Answers

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

like image 112
Schorty Avatar answered Sep 28 '22 16:09

Schorty