This is a quick and dirty way of implementing CORS in a Rails app. DO NOT DO THIS IN A PROFESSIONAL SETTING
- Go to
app/controllers/application_controller.rband comment out theprotect_from_forgeryline. - Go to your Gemfile and add the following line to the bottom :
gem 'rack-cors', :require => 'rack/cors' - Run
bundle - Go to
config/application.rband add the following code to the bottom of theApplicationclass definition:
config.middleware.use Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :put, :patch, :delete, :options]
end
end- If you haven't already, restart the Rails server; then, serve up your front-end and start making requests!
Ruby : 2.2.0
Rails: 4.2.1
Bundler: 1.10.2
Postgres: 9.4.2.0
