When saving nested resources (ex saving a highlight that belongs to a property) it seems that Ember doesn't pickup on the nested route hierarchy and 'POSTS' to just 'api/v1/highlights' when i need it to 'POST' to 'api/v1/properties/property_id/highlights'. So I thought about un-nesting the routes on the back-end to solve it and passing the property_id somehow, but it would be a lot easier to just be able to have it understand the correct route. I came across the buildURL mixin to build the correct path for each time and was wondering if that's the best way to do it and is there something I'm doing wrong?
Thanks for all the help in advance
Here are parts of my code...
routes.rb
namespace :api, defaults: { format: :json } do
namespace :v1 do
resources :users, only: [:show, :update]
resources :user_devices, only: [:show]
resources :properties do
resources :highlights do
resources :options
end
end
resources :fields
end
end
router.js
this.route('properties', function() {
this.route('new');
this.route('property', {path: ':property_id'}, function() {
this.route('edit');
this.route('details');
this.route('highlights', function() {
this.route('new');
this.route('highlight', {path: ':highlight_id'}, function() {
this.route('edit');
this.route('options', function() {
this.route('new');
this.route('option', {path: ':option_id'}, function() {
this.route('edit');
});
});
});
});
adapter
import Ember from 'ember';
export default Ember.Mixin.create({
host: 'http://localhost:3000',
namespace: 'api/v1'
});
highlight model in highlight.js
property: DS.belongsTo('property', {async: true }),
property model in property.js
highlights: DS.hasMany('highlight', {async: true }),
Aucun commentaire:
Enregistrer un commentaire