Alive Developer
Alive Developer

Reputation: 1022

Ember.js: how to get my current_user info with no requests

I'm a beginner with ember.js, and i don't know the best way to do this:

my application has devise gem, and it's a server side mvc application until you log in. Then it's ingle page. So all my ember code is declared inside the "inner" layout. In this layout, obviously, i also have my current_user.name method. I would like to use this information, and not doing an http request to get it. I think that if there could be a way to put it inside my applicationController... it would be perfect! Any ideas? Or maybe i'm trying to do the wrong thing?

thanks,

Marco

Upvotes: 1

Views: 186

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

You can embed your current_user's json in a data-current-user attribute on the body.

<body data-current-user="<%= current_user.to_json %>">

This way you can check if they are authenticated, and get their attributes without an HTTP call.

Ryan Bats goes into detail on this: http://railscasts.com/episodes/324-passing-data-to-javascript

Upvotes: 1

Related Questions