Created
October 8, 2015 17:48
-
-
Save danielalvarenga/672661b3c41526601e51 to your computer and use it in GitHub Desktop.
Add Header params to configure CORS for Rails 4 API
This file contains 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
before_filter :allow_cors | |
def allow_cors | |
headers["Access-Control-Allow-Origin"] = "*" | |
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE OPTIONS}.join(",") | |
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-Prototype-Version X-CSRF-Token token}.join(",") | |
headers['Access-Control-Max-Age'] = "1728000" | |
if request.method == 'OPTIONS' | |
render :text => '', :content_type => 'text/plain' | |
end | |
end |
This file contains 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
# permit options method | |
match "path/to/action" => "controller#action", via: [ :post, :options] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment