I'm trying to detect whether request is xhr or not in ApplicationController by using
request.xhr?
It always returns 0.
But headers tell otherwise;
request.headers["X-Requested-With"] ==> "XMLHttpRequest"
@_env['HTTP_X_REQUESTED_WITH'] ==> "XMLHttpRequest"
What am I missing?
version is Rails 4.0.0
request.xhr? always returns Object or nil, not true or false, since it's based on regexp pattern matching (see here).
In Ruby, any value other than false and nil is a truthy value (as is the 0 returned by request.xhr?), so the response is correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With