I\'m just about to pull my hair out... I\'ve been trying to enable CORS in this Rails app since the morning and it just doesn\'t work. I\'ve tried this, using Rack Cors Gem
Rack::Cors provides support for Cross-Origin Resource Sharing
Steps to enable rackcors :
1.add gem to your Gemfile:
gem 'rack-cors'
2.Add below code to config/application.rb
# if you are using Rails 3/4
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => :any
end
end
# if you are using Rails 5
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: :any
end
end