Skip to content

Instantly share code, notes, and snippets.

@changs
Created May 23, 2012 14:28
Show Gist options
  • Save changs/2775511 to your computer and use it in GitHub Desktop.
Save changs/2775511 to your computer and use it in GitHub Desktop.
before_filter :pre_cors
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Max-Age'] = "1728000"
end
def pre_cors
if request.method == :options
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version'
headers['Access-Control-Max-Age'] = '1728000'
render :text => '', :content_type => 'text/plain'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment