Open ericeslinger opened 11 years ago
There are several options for doing this. Soon I would like to officially support urls for collections and models, but for now I would use a remoteCall: session.remoteCall('user', 'current')
. This should load that 'api/users/current' endpoint and load whatever data is serialized back. (there might be an issue with GET
requests and remoteCall
but I can easily fix if that is the case.)
session.remoteCall('user','current') does indeed use POST to get to api/users/current, but I was able to provide a post route there. However, the returned object still gives an error in the same place.
Social.ProfileRoute = Ember.Route.extend
model: ->
@session.remoteCall('user','current')
<h2>Profile page</h2>
Hello {{name}}!
still getting the same error referenced above related to stringifying the clientid.
The endpoint returns
{"user":{"name":"Eric Eslinger","email":"eric.eslinger@gmail.com","id":3}}
Use case: I have a /api/users/:user_id resource that serves up relevant JSON about users of my system. I also make use of the session store to keep track of which user_id the current user is logged in as, and serve that up as /api/users/current.
The user object JSON includes an id field, but either because the id in the API path (which I retrieve by doing a @session.find 'user', 'current') is a string, or doesn't match the actual id field in the returned JSON, the system chokes with an error.
Uncaught TypeError: Cannot call method 'toString' of undefined epf.js?body=1:2765 Ep.Adapter.Ember.Object.extend._typeToString epf.js?body=1:2765 Ep.Adapter.Ember.Object.extend._generateClientId epf.js?body=1:2762 Ep.Adapter.Ember.Object.extend.reifyClientId epf.js?body=1:2750 Ep.Session.Ember.Object.extend.reifyClientId epf.js?body=1:3322 Ep.Session.reopen.merge epf.js?body=1:2980 (anonymous function) epf.js?body=1:3251 invokeCallback ember.js?body=1:7252 (anonymous function) ember.js?body=1:7302 EventTarget.trigger ember.js?body=1:7075 (anonymous function) ember.js?body=1:7365 DeferredActionQueues.flush ember.js?body=1:4727 Backburner.end ember.js?body=1:4813 (anonymous function)