I'm following a tutorial to learn the basics of API and I'm having troubles setting everything up. This is what I've done:
Rails.application.routes.draw do
namespace :api, constraints: {format: :json} do
resources :kittens
end
end
#app/controllers/api/kittens_controller.rb
class API::KittenController < ApplicationController
def index
end
end
#config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'API'
end
The error I get when visiting /api/kittens
Unable to autoload constant API::KittensController, expected /media/Volume.II/Dropbox/Web Development/odin-project/3. Ruby on Rails/odin-kittens/app/controllers/api/kittens_controller.rb to define it
Extracted source (around line #495):
else
require_or_load(expanded, qualified_name)
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
return from_mod.const_get(const_name)
end
elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
Any help would be really appreciated. Thanks.
You have a typo in your class name: API::KittenController
instead of API::KittensController
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With