Nel mio file config/application.rb
, ho questo codice,Consenti CORS in Ruby on Rails
config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => 'GET, PATCH, PUT, POST, OPTIONS, DELETE'
}
Ma questo non mi permette di inviare una richiesta di post per un percorso sul mio sever
Safari dà a questo errore:
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
E nella mia console del server Rails:
Started OPTIONS "/students" for ::1 at 2015-03-28 21:00:45 -0500
ActionController::RoutingError (No route matches [OPTIONS] "/students"):
questo dovrebbe funzionare. io uso 'ActionDispatch :: Static' come primo argomento invece di' 0'. –
Questo ha funzionato molto bene per me. @ReydiSutandang, perché hai suggerito 'ActionDispatch :: Static' invece di' 0'? – andreshg112
Ora che ho lavorato con un nuovo progetto, ho notato che questa soluzione ha molto senso per esigenze più complesse. L'ho selezionato come risposta migliore –