Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "Origin" request header in Rails

How do I get the Origin request header from cross-domain AJAX requests in Rails?

like image 273
William Avatar asked Apr 02 '14 13:04

William


2 Answers

You can achieve this in the controller by using:

request.headers['origin']

Note: You will need to make certain changes in certain config files for your application to be able to respond to a CORS request. Hope you've got that covered.

like image 193
Ritikesh Avatar answered Oct 16 '22 22:10

Ritikesh


It seems like request.origin also works directly in recent rails versions. (at least Rails 6)

like image 1
Cyril Duchon-Doris Avatar answered Oct 16 '22 23:10

Cyril Duchon-Doris