Skip to content

Instantly share code, notes, and snippets.

@ckozus
Created March 25, 2013 14:08
Show Gist options
  • Save ckozus/5237351 to your computer and use it in GitHub Desktop.
Save ckozus/5237351 to your computer and use it in GitHub Desktop.
class RequestsController < ApplicationController
def create
if access_allowed?
set_access_control_headers
head :created
else
head :forbidden
end
end
def options
if access_allowed?
set_access_control_headers
head :ok
else
head :forbidden
end
end
private
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = request.env['HTTP_ORIGIN'] # '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Max-Age'] = '1000'
headers['Access-Control-Allow-Headers'] = 'Content-Type' #'*, X-Requested-With' #'*, Origin, Content-Type, Accept, X-Requested-With, X-CSRF-Token' #'Authorization'
headers['Content-Type'] = 'text/plain'
headers['Access-Control-Allow-credentials'] = 'true'
end
end
match '*request', :controller => 'requests', :action => 'options', :constraints => {:method => 'OPTIONS', :format => 'json'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment