Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Created May 4, 2014 15:20
Show Gist options
  • Save simonmorley/24f1492e8515d1038d29 to your computer and use it in GitHub Desktop.
Save simonmorley/24f1492e8515d1038d29 to your computer and use it in GitHub Desktop.
Public API Cors Before Filter Rails API
before_filter: cors_filters
def cors_filters
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
end
@simonmorley
Copy link
Author

Shove this in a controller to allow cors requests in a Ruby on Rails application.

We use for the interface with an AngularJS application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment