Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL Aliasing for RESTFul models #55

Open
ericeslinger opened this issue Aug 6, 2013 · 2 comments
Open

URL Aliasing for RESTFul models #55

ericeslinger opened this issue Aug 6, 2013 · 2 comments

Comments

@ericeslinger
Copy link

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)

@ghempton
Copy link
Contributor

ghempton commented Aug 6, 2013

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.)

@ericeslinger
Copy link
Author

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}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants