Daniel Tonon
Daniel Tonon

Reputation: 10432

Ember tutorial error: models/rental.js: line 4, col 12, 'attr' is not defined

I'm going through the main tutorial on the ember website and I got to the end of this page: https://guides.emberjs.com/v2.5.0/tutorial/ember-data/

In the command prompt ember is saying this

models/rental.js: line 4, col 12, 'attr' is not defined.

It is referencing this bit

export default Model.extend({
    title: attr(),
    owner: attr(),
    city: attr(),
    type: attr(),
    image: attr(),
    bedrooms: attr()
});

When I reach the bottom of the tutorial, the page is just completely blank when it loads.

When I delete the title: attr(), bits that are erroring, the error goes away and the page loads the hard coded HTML but the variable fields aren't populated with anything. The looping functionality does occur though.

Can someone please help me figure out where I'm going wrong?

Upvotes: 0

Views: 392

Answers (2)

Muhammad Ateek
Muhammad Ateek

Reputation: 1057

Please define you model in this path

app/models/rental.js

then include following code in renatal.js file

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

export default Model.extend({
  title: attr(),
  owner: attr(),
  city: attr(),
  type: attr(),
  image: attr(),
  bedrooms: attr()
});

basically you are not importing attr and Model libraries from ember-data.

Upvotes: 0

dynamic_cast
dynamic_cast

Reputation: 1105

You may have forgot to import attr as shown in the tutorial :

import attr from 'ember-data/attr';

Upvotes: 4

Related Questions