When and how to use different object model?


Example: My rails API provides a json with attributes username, image and email. I do not want the email to be public so that everyone can use my API and get users email addresses, but I want a user to be able to change their email.

The best solution for this (in a rails way) would be that ‘api/users/:id.json’ returns username and image and ‘api/users/:id/edit.json’ returns username, image and email. That’s at least how I had done if this was just a rails app.

How do I solve this in ember? I could create a UserBase model (username, email) and a UserDetails model (email) that’s extends from UserBase but further than that have I don’t come.

In the users edit route how can I specify so that UserDetails model is used? And how can I tell ember-data to find the user through ‘api/users/:id/edit.json’? I want to find the user through ‘api/users/:id/edit.json’ so I can check backend so current user has permission to read that data.

My English is not the best but I hope you understand how I think and what I want to do, thanks!


api/users/:id/edit.json doesn’t really sound RESTful. I would just create one api/users/:id.json resource. Based on the current logged in user, the server determines whether to include the email address in the returned JSON.

Perhaps you can substitute the email with a special string like _redacted_. In Ember you could then check whether the email address was included in the response and act appropriately.


Thank you! Stupid of me not to think further than that