Skip to content

Instantly share code, notes, and snippets.

@dmitriy-kiriyenko
Created October 5, 2012 07:56
Show Gist options
  • Save dmitriy-kiriyenko/3838649 to your computer and use it in GitHub Desktop.
Save dmitriy-kiriyenko/3838649 to your computer and use it in GitHub Desktop.
Solve of cross-domain ajax requests

Cross-origin resource sharing

  • Use rack-cors
  • Add it to middleware
  • Adjust permissions if you want
  • May the force be with you
# Add it to config/application.rb
module YourApplicationName
class Application < Rails::Application
config.middleware.use Rack::Cors do
# Allow everything to everyone
# Instead in block `allow` you can use constraints
# to achieve some security.
# More on this options here: https://github.com/cyu/rack-cors
allow do
origins '*'
resource '*',
:methods => [:get, :post, :put, :delete, :options],
:headers => :any
end
end
end
end
# Add it to Gemfile
gem 'rack-cors', :require => 'rack/cors'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment