javascript - Ember data from Mirage fails to display on index.hbs -
ember novice here. have been following along tutorial on ember website here.
i have been r&d'ing example word , works...until try implementing mirage. data never shows on index.hbs page.
here's model hook:
import ember 'ember'; export default ember.route.extend({ model() { return this.store.findall('rental'); }, });
and model: rental.js
import ds 'ember-data'; export default ds.model.extend({ title: ds.attr('string'), owner: ds.attr('string'), city: ds.attr('string'), type: ds.attr('string'), image: ds.attr('string'), bedrooms: ds.attr('number') });
my index.hbs:
<h1> welcome super rentals </h1> hope find you're looking in place stay. {{#each model |rentalunit|}} {{rental-listing rental=rentalunit}} {{/each}} {{#link-to "about"}}about{{/link-to}} {{#link-to "contact"}}click here contact us.{{/link-to}}
and lastly app/mirage/config.js:
export default function() { this.get('/rentals', function() { return { data: [{ type: 'rentals', id: 1, attributes: { title: 'grand old mansion', owner: 'veruca salt', city: 'san francisco', type: 'estate', bedrooms: 15, image: 'https://upload.wikimedia.org/wikipedia/commons/c/cb/crane_estate_(5).jpg' } }, { type: 'rentals', id: 2, attributes: { title: 'urban living', owner: 'mike teavee', city: 'seattle', type: 'condo', bedrooms: 1, image: 'https://upload.wikimedia.org/wikipedia/commons/0/0e/alfonso_13_highrise_tegucigalpa.jpg' } }, { type: 'rentals', id: 3, attributes: { title: 'downtown charm', owner: 'violet beauregarde', city: 'portland', type: 'apartment', bedrooms: 3, image: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/wheeldon_apartment_building_-_portland_oregon.jpg' } }] }; }); }
i 2 messages in chrome developer console:
mirage: ember app tried 'http://localhost:4200/assets/vendor.js', there no route defined handle request. define route matches path in mirage/config.js file. did forget add namespace?
and warning:
warning: encountered "data" in payload, no model found model name "datum" (resolved model name using super-rentals@serializer:-rest:.modelnamefrompayloadkey("data"))
however looks info sucessfully retrieved see a:
successful request: /rentals object {data: array[3]}
which reflects proper data. breaking somewhere between , index.hbs , novice figure out. i'm sure it's small misunderstanding on part. appreciated!
you have wrong version of ember data installed. make sure restart server time install dependency.
the error message getting means application using restadapter (the default adapter ember data 1.x). why looks @ top-level data
key , tries singularize , find related model.
you can update following instructions on latest ember cli release. or, can npm install -g ember-cli@beta
, start scratch.
Comments
Post a Comment