Given your last comment, your problem is related to session only. It is not linked to the definition of you current_user
method.
By default, a Rails 3 application resets the session when there is no authentication token in a HTTP POST request. The behaviour is slightly different with Rails 4 (depending on the configuration) but you would have a similar problem at the end.
I guess your ajax queries don't contain authentication token, hence the warning WARNING: Can't verify CSRF token authenticity
, hence the empty session. With an empty session you current_user
method will always return nil
, unless you are inside a GET request and you haven't made any POST request since authentication.
I don't write a solution here because it is no simple (it depends on the javascript framework you use) and it has no link with your original question.
You should read the answer of this question: WARNING: Can't verify CSRF token authenticity rails