简体   繁体   中英

nil current_user response to json

I found a demo app that implements devise with Backbone. In the layout file, it does this

$(function(){
        BackDevise.initialize(<%= current_user.to_json.html_safe %>);
    })

If I start the application without being logged in, there is obviously no current_user, but the application doesn't throw an error. Why? ie normally, when I use Devise with Rails, I have to do a lot of <% if current_user ... %> checks to see if the user is logged in. Why wouldn't this code need anything like that? Note, the code doesn't (as far as I can see) override the current_user helper provided by Devise, so I would have expected it to throw an exception if I'm not logged in.

原因nil响应to_json并返回"null"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM