Last active
August 29, 2015 14:01
-
-
Save camsong/0e162b83a103f21ad7b7 to your computer and use it in GitHub Desktop.
CORS enabled in Rails 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_action :cors_set_access_control_headers | |
def options | |
head :ok | |
end | |
private | |
def default_serializer_options | |
{ root: false } | |
end | |
def cors_set_access_control_headers | |
headers['Access-Control-Allow-Origin'] = '*' | |
headers['Access-Control-Allow-Methods'] = 'PUT, POST, GET, OPTIONS' | |
headers['Access-Control-Request-Method'] = '*' | |
headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With, X-Prototype-Version' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
match '*path', to: 'application#options', via: :options | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment