0

Is it possible to load every file in app/scripts/models directory automatically or do I have to reference every single file in index.html?

I want to have a model-per-file for my Ember app and that would make a lot of lines. Don't want to write redundant code.

mreq
  • 6,414
  • 4
  • 37
  • 57

1 Answers1

1

Yes it's possible, and if you are using yeoman (at the last version) and you have generated an ember.js app with:

yo ember:all

you should have a app.js in myproject/scripts/app.js, where inside the file at the top (somewhere starting from line 10) you have this code lines which are commented:

require('app/scripts/routes/*');
require('app/scripts/controllers/*');
require('app/scripts/models/*');
require('app/scripts/views/*');

uncomment them and the build process should be able to pickup your single model files and also other files like views, controllers etc. you have in the directories specified above.

Update

It's also worth mentioning that responsible for the require statement is the grunt module grunt-neuter, so you should have it also defined as a dependency in your Gruntfile.js

Hope it helps.

intuitivepixel
  • 23,302
  • 3
  • 57
  • 51
  • There are no such lines. If I try to add them manually, JS complains there's no such function as require. Note that I'm using coffeescript, but that shouldn't matter. – mreq Jun 24 '13 at 20:29
  • do you have the last yeoman version (1.0 beta) and did you build generate your project with the command mentioned above (which you get by installing the `generator-ember` https://github.com/yeoman/generator-ember)? – intuitivepixel Jun 24 '13 at 21:59
  • Yes I have `yo@1.0.0-beta.7` and `generator-ember` and did it the way you described. Strange. – mreq Jun 24 '13 at 22:20
  • yes strange, because see here: https://github.com/yeoman/generator-ember/blob/master/app/templates/scripts/app.js this is the file the `generator-ember` uses for the generated `app.js` and in the case younare using coffescript it's this file: https://github.com/yeoman/generator-ember/blob/master/app/templates/coffeeScript/app.coffee – intuitivepixel Jun 24 '13 at 22:23