Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aesthetikx/ember_nested_rails
Experiment to get Ember to work with nested resource routes
https://github.com/aesthetikx/ember_nested_rails
Last synced: about 2 months ago
JSON representation
Experiment to get Ember to work with nested resource routes
- Host: GitHub
- URL: https://github.com/aesthetikx/ember_nested_rails
- Owner: Aesthetikx
- Created: 2015-06-14T20:26:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-15T15:57:47.000Z (over 9 years ago)
- Last Synced: 2023-08-22T14:54:09.447Z (over 1 year ago)
- Language: Ruby
- Size: 19.6 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ember Nested Rails
##Configure Rails to generate ember-esque json
```ruby
# config/initializers/active_model_serializer.rb
ActiveModel::Serializer.setup do |config|
config.embed = :ids
config.embed_in_root = true
end# app/serializers/post_serializer.rb
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :body
has_many :comments
end# app/serializers/comment_serializer.rb
class CommentSerializer < ActiveModel::Serializer
attributes :id, :body
end
```##Configure Ember to use nested routes
```javascript
// frontend/app/adapters/post.js
import DS from "ember-data";
import UrlTemplates from "ember-data-url-templates";export default DS.ActiveModelAdapter.extend(UrlTemplates, {
urlTemplate: '{+host}/api/posts/{/id}',
});// frontend/app/adapters/comment.js
import DS from "ember-data";
import UrlTemplates from "ember-data-url-templates";export default DS.ActiveModelAdapter.extend(UrlTemplates, {
urlTemplate: '{+host}/api/posts/{postId}/comments{/id}',urlSegments: {
postId(type, id, snapshot, query) {
return snapshot.belongsTo('post', { id: true });
},
}
});
```