Ich erstelle einen einfachen API-Endpunkt in meiner Rails 4.2.6 App, habe aber Probleme damit.Kontinuierlicher API-Controller kann nicht automatisch in Rails geladen werden 4
Wenn ich die URL getroffen: http://lvh.me:9077/api/v1/grubs Ich erhalte den folgenden Fehler:
Unable to autoload constant Api::V1::GrubsController, expected /Users/shakycode/code/grubs/app/controllers/api/v1/grubs_controller.rb to define it
Hier meine routes.rb Datei wird den Endpunkt definieren. Hier
namespace :api do
namespace :v1 do
resources :grubs, only: [:index]
end
end
ist meine app/controllers/api/v1/grubs_controller.rb
class API::V1::GrubsController < ApplicationController
protect_from_forgery with: :null_session
before_action :destroy_session
def destroy_session
request.session_options[:skip] = true
end
def index
@grubs = Grub.all
respond_to do |format|
format.json { render json: @grubs}
end
end
end
ich eine Rails 4.2.1 app, wo ich die gleiche Strategie verwendet, aber in 4.2.6 I‘ Dieser Fehler tritt auf, wenn ich versuche, gegen die API zu ziehen.
Vielen Dank im Voraus!
Update: Hier ist die Ausnahme, die im Browser better_errors angehoben wird:
load_missing_constantactivesupport (4.2.6) lib/active_support/dependencies.rb
490
491
492
493
494
495
496
497
498
499
500
if loading.include?(expanded)
raise "Circular dependency detected while autoloading constant #{qualified_name}"
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)
return mod
elsif (parent = from_mod.parent) && parent != from_mod &&
Dies! Es sagt sogar, 'Kann nicht konstant laden Api :: V1 :: GrubsController, erwartete /Users/shakycode/code/grubs/app/controllers/api/v1/grubs_controller.rb, um es zu definieren. Weil 'grubs_controller.rb' einen' API :: V1 :: GrubsController' definiert, aber keinen 'Api :: V1 :: GrubsController'. – fbelanger