Let me explain shortly what I mean. I'm writing an app that makes use of Ember and Rails. Every employee can give other co-workers a kudo. He can't know how many others received. I can only know how many left kudos I have to give and how many I received from others.
But I can't really understand how to communicate with Rails. As a picture is worth a thousand words, please take a look at this: kudos app http://wstaw.org/m/2013/03/25/kudos.png
When the app starts I load a list of users pointing to /users. Current user is at /currentuser. Current user differs in that it has additional fields like kudosReceived and kudosLeft.
Let's suppose I'd like to add Joe a kudo. I click on a button, and then, what? Suppose that when I go to /kudos/userid rails will do its magic. It just adds Joe a kudo. But I'd also like to get the updated current user data (remember, it is at /currentuser).
What should I send? Should I first use CREATE or UPDATE method on the controller? How can I obtain current user new data? In a callback? Or should I use /currentuser with GET. But when?
This is what I have now, but I'm completely unsure how correct it is
// application.handlebars
<h1>My Kudos</h1>
<div id="kudos-content">
<ul id="kudos-list">
{{#with controllers.current}}
<li>
<p>{{firstName}} {{lastName}}</p>
<p><img {{bindAttr src="imageUrl"}} /></p>
<p>received: {{kudosReceived}}</p>
<p>left: {{kudosLeft}}</p>
</li>
{{/with}}
{{#each user in controllers.users}}
<li>
<p>{{user.firstName}} {{user.lastName}}</p>
<img {{bindAttr src="user.imageUrl"}} />
<a href="#" {{action "addKudo" user.id target="controller.controllers.kudo"}}>(+)</a>
</li>
{{/each}}
</ul>
</div>
Sks.KudoController = Ember.ObjectController.extend({
addKudo: function(userId) {
// create a new record on a local transaction
this.transaction = this.get('store').transaction();
// don't really know what next
}
});
The next problem is how to use /kudo/userid in {{action}}