Skip to content

Instantly share code, notes, and snippets.

@davelyon
Created May 23, 2011 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davelyon/986681 to your computer and use it in GitHub Desktop.
Save davelyon/986681 to your computer and use it in GitHub Desktop.
Cross-Origin Resource Sharing on Rails
def cross_site_sharing
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = 'POST, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'X-Requested-With'
headers['Access-Control-Max-Age'] = '1278000'
headers['Content-Length'] = '0'
headers['Content-Type'] = 'text/plain'
render nothing: true, status: 200
end
## in 'routes.rb'
match '(your_path)', to: '(controller)#cross_site_sharing', via: :options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment