I have a Rails API and EmberCLI frontend app. My page shows a list of artists. Click on artist should send user on page with all albums of the artist. I need to make a link to user's albums page. Each artist has his own page with albums. Like localhost:4200/artists/1. Here's what I have:
My router:
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('artists');
this.route('artist', { path: 'artist/:artist_id' });
});
export default Router;
model Artist:
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
itunes_id: DS.attr('number'),
albums: DS.hasMany('album')
});
model Album:
import Model from 'ember-data/model';
import DS from 'ember-data';
export default Model.extend({
name: DS.attr('string'),
artwork_url_100: DS.attr('string'),
artist_id: DS.attr('number'),
artist: DS.belongsTo('artist')
});
Routes: 1)artist.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('artist')
return this.store.findRecord('artist', params.artist_id);}
});
2) album.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('album');}
});
Aucun commentaire:
Enregistrer un commentaire