getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
368 stars 33 forks source link

Load data into the epf session from an AJAX request and does the RESTAdapter make calls to custom rails controller actions #14

Closed mankind closed 11 years ago

mankind commented 11 years ago

1. How to do I add data either into a new epf session or add the data to an existing session after making an AJAX request like the one shown below. Also is that the right way to access a session from the controller. Do I use session.merge or will it be session.load

App.MyController = Ember.ArrayController.extend({

   foo: function() {

       $.post("/signIn", function(data) {
          // here is where I want to load the data into the session
         this.get('session').load(App.User, data.users);

          //or do I use
         this.session.merge(App.User, data.users)
       });
    }
});

or do I use this.adapter.load(type, id) as in this.get('session').adapter.load(App.User, data.users) I got that by reading the source code link below:

https://github.com/GroupTalent/epf/blob/master/lib/session/session.js#L224

2. Does the RESTAdapter make calls to custom rails controller actions.

After reading the source here:

https://github.com/GroupTalent/epf/blob/master/test/rest/rest.rpc.em#L20

It seems that is what the remoteCall method does, but I am correct?

If I am correct, will this be the right way to update the rails controller action to true using remoteCall where the url is tasks/:id/complete. The rails controller code is pasted after the epf code below:

   session.remoteCall(task, submit: 'true')

This is the rails controller with an action called complete:

 class TasksController < ApplicationController
   def complete
     @task = @list.tasks.find(params[:id])
     @task.completed = true
     @task.save
   end
 end

The rails route could look like this or the one underneath:

match 'tasks/:id/complete' => 'tasks#complete'

In the database, complete is a boolean:

create_table "tasks", :force => true do |t|
  t.boolean "completed", :default => false  
end
ghempton commented 11 years ago

1: For this you could just manually create the model and then merge it into the session: E.g.:

user = App.User.create(...);
session.merge(user);

2: Yup, remoteCall should be used here. You can optionally return models from the action that will be updated on the client.

I am going to close this issue for now, but feel free to keep the questions coming!