In meiner config/application.rb
Datei, ich diesen Code haben,zulassen CORS in Ruby on Rails
config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => 'GET, PATCH, PUT, POST, OPTIONS, DELETE'
}
Aber das erlaubt mir nicht, auf meinem Sever
Safari ergibt dies eine Post-Anforderung an eine Route zu schicken Fehler:
http://localhost:3000/studentsFailed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/studentsFailed to load resource: Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin.
localhost:1XMLHttpRequest cannot load http://localhost:3000/students. Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origi
Und in meiner Rails-Server-Konsole:
Started OPTIONS "/students" for ::1 at 2015-03-28 21:00:45 -0500
ActionController::RoutingError (No route matches [OPTIONS] "/students"):
sollte dies funktionieren. Ich verwende 'ActionDispatch :: Static' als erstes Argument anstelle von' 0'. –
Das hat sehr gut für mich funktioniert. @ReydiSutandang, Warum hast du "ActionDispatch :: Static" anstelle von "0" vorgeschlagen? – andreshg112
Jetzt, wo ich mit einem neuen Projekt gearbeitet habe, habe ich bemerkt, dass diese Lösung sehr sinnvoll für kompliziertere Bedürfnisse ist. Ich habe es als die beste Antwort gewählt –