开发者

Current_user devise method returns nil outside the user controller

开发者_JAVA百科Is this a scope/routes problem? The current_user works in the user controller. Outside, in another controller/view, this returns nil. Even if the user is logged in, the user_signed_in? method returns false. I know I am missing something, just not able to point my finger. What is the right way to do this?


It works for me in other controllers. A wild guess: maybe the other controller needs: before_filter :authenticate_user!


Found the problem. It was the sessions. Apparently, the current_user and other methods were not behaving right because of cookies. I had subdomains and the problem was because of that https://github.com/fortuity/rails3-subdomain-devise/wiki/Tutorial-%28Walkthrough%29. This git tutorial helped.

Thanks!


I was having the same problem, I needed to put this in my layout, I was using a different layout than application:

= csrf_meta_tags


Same thing happened to me but the problem was when I made an ajax request. This fixed it (in haml). This makes sure that all ajax request carry the csrf token:

:coffee
  require ['jquery'], ($)->
    $.ajaxSetup
      headers:
        'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')

Make sure this is in the header:

= csrf_meta_tags
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜