With devise one uses before_filter :authenticate_user!
to restrict access to authenticated users only.
When an unauthenticated
As of Rails 5.1 and the new rails-ujs, all custom events return only one parameter: event
. In this parameter, there is an additional attribute detail
which contains an array of extra parameters. The parameters data
, status
, xhr
have been bundled into event.detail
. So handling the 401 error in ajax with the ajax:error
event becomes:
document.body.addEventListener('ajax:error', function(event) {
var detail = event.detail;
var response = detail[0], status = detail[1], xhr = detail[2];
if (xhr.status == 401) {
// handle error
}
})