Update : Dies war auf einen falsch geschriebenen Dateinamen zurückzuführen
richtig:~/sample_app/app/controllers/microposts_controller.rb
falsch:~/sample_app/app/controllers/microposts_contoller.rb
Dies ist mein erster Beitrag hier, Feedback zur Verbesserung dieser oder zukünftiger Beiträge wird gebeten :)
Ruby on Rails Tutorial: Lernen Sie Webentwicklung mit Rails 4
Beim Abarbeiten des Kapitels 10.3 blieb ich hängen. Am Ende hatte ich mit einem falsch geschriebenen Dateinamen ein paar Tage lang Geister gejagt.
$ rspec spec/requests/authentication_pages_spec.rb
No DRb server is running. Running in local process instead ...
...FF................
Failures:
1) Authentication authorization for non-signed-in users in the Microposts controller submitting to the create action
Failure/Error: before { post microposts_path }
ActionController::RoutingError:
uninitialized constant MicropostsController
# ./spec/requests/authentication_pages_spec.rb:93:in `block (6 levels) in '
2) Authentication authorization for non-signed-in users in the Microposts controller submitting to the destroy action
Failure/Error: before { delete micropost_path(FactoryGirl.create(:micropost)) }
ActionController::RoutingError:
uninitialized constant MicropostsController
# ./spec/requests/authentication_pages_spec.rb:98:in `block (6 levels) in '
Finished in 0.92253 seconds
21 examples, 2 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:94 # Authentication authorization for non-signed-in users in the Microposts controller submitting to the create action
rspec ./spec/requests/authentication_pages_spec.rb:99 # Authentication authorization for non-signed-in users in the Microposts controller submitting to the destroy action
Dies lag an einem falsch geschriebenen Dateinamen ~/sample_app/app/Controllers/microposts_controller.rb (war microposts_contoller.rb)
Dies kann auch passieren, wenn Sie eine verschachtelte Route haben, die ein verschachteltes Verzeichnis darstellt:
Started POST "/brokers/properties/5/images/upload" for ...
ActionController::RoutingError (uninitialized constant Brokers::ImagesController):
namespace :brokers do
resources :properties, only: [] do
collection do
post 'upload'
end
member do
resources :images, only: [] do
collection do
post 'upload'
end
end
end
end
end
Sie müssen Ihre images_controller.rb
-Datei mit der folgenden Struktur platzieren:
-controllers
|-brokers
|-images_controller.rb
Hinweis in der Verzeichnisstruktur images_controller.rb
ist ein direkter Nachkomme von Brokern.
Damit Rails feststellen kann, dass Ihre Klasse kein Unterverzeichnis properties
in brokers
erstellt, das die Routenstruktur darstellt, muss es direkte Nachkommen von Brokern sein
In routes.rb
habe ich resource
anstelle von resources
eingegeben.
Nur um zu helfen, wenn jemand bei einem ähnlichen Problem stecken bleibt:
Ich habe den Controller falsch geschrieben, wenn Sie ohne die s in Produkte eingeben es war falsch:
Falsch:
get '/my_products', to: 'product#my_products'
Recht:
get '/my_products', to: 'products#my_products'
Ich hatte das Folgende falsch in meinen application_controller.rb
eingefügt.
Richtig: include ActionController::MimeResponds
Falsch: include ActionController::MimeResponse
# /controllers/api/v1/application_controller.rb
module Api
module V1
class ApplicationController < ActionController::API
include ActionController::MimeResponds
end
end
end
in meinen Routen: Ich hatte "/" anstelle von "#" für alle "get", also ändern Sie diese in "#" erhalten 'all' => 'storefront # all_items'
get 'categorical' => 'Storefront # items_by_category'
get 'branding' => 'Storefront # items_by_brand'
das hat alle meine fehler behoben.