0

Using flat route (if a view has to be displayed in a separate view) structure solves many problems and helps to avoid unnecessary code, but all templates in a root template dir are more than mess:

For example:

(using ember-rails)

AddressBook.Router.map () ->
  @resource 'contacts'
  @resource 'contact', path: '/contacts/:contact_id'
  @resource 'contactNew', path: '/contacts/new'
  @resource 'contactEdit', path: '/contacts/:contact_id/edit'

all templates for routes defined above have to be in the root directory. With more routes it'd be more than a problem to maintain it.

Is it possible to keep templates in order? Or maybe something has changed when it comes to Ember router?

GJK
  • 37,023
  • 8
  • 55
  • 74
wryrych
  • 1,765
  • 4
  • 20
  • 31

1 Answers1

1

I'm assuming that you're using some kind of Handlebars pre-compiler which is getting the template name from the path. (I've never used rails, so I don't know if that's built into Ember-rails.) If that's the case, I think you have two options.

  1. You could attempt to modify/configure the pre-compiler so that it takes the template name from somewhere other than the path. I don't know which one you're using, so I can't really give you details.

  2. You can change the template that the route renders. You could use the render method of Route, or you could defined the view for the route and change the layoutName property.

Personally, I would highly suggest taking advantage of nested routes, as they offer many other benefits besides template organization. But if you really don't want to, look up documentation on your pre-compiler and try option number 1. You might be able to come up with something clever.

EDIT: With Ember-Rails, option 1 is probably the best. I don't know anything about Ruby, but I'm pretty sure everything you need is in template.rb.

GJK
  • 37,023
  • 8
  • 55
  • 74
  • Yup we're using a pre-compiler that comes from `ember-rails` gem. But as for nested routes, have you seen this article: http://hashrocket.com/blog/posts/ember-routing-the-when-and-why-of-nesting? – wryrych Apr 03 '14 at 07:29
  • He's not saying that flat routes are better, he's saying that they're better suited for certain situations. But Ember is built around hierarchies; templates, routes, controllers, views, etc. And since that article was written, there have been many bugfixes and many new features added to eliminate boilerplate in nested objects. I think it's safe to say that in most situations, you'd actually write _more_ code and boilerplate with a flat structure. – GJK Apr 03 '14 at 11:47
  • Could you give some links to articles / posts that describe updated router / routing in Ember and how much more code and boilerplate I can avoid not using flat structure? – wryrych Apr 04 '14 at 07:31
  • Well as of [1.5.0](http://emberjs.com/blog/2014/03/30/ember-1-5-0-and-ember-1-6-beta-released.html), routes inherit their parent model, which is really nice. But nested routes also allow [event bubbling](http://emberjs.com/guides/templates/actions/) and make using the [loading and error](http://emberjs.com/guides/routing/loading-and-error-substates/) substates much easier to use. – GJK Apr 04 '14 at 11:57
  • OK, got it. Were're going to upgrade to newest stable Ember / Ember-Data in the following weeks so we'll take a closer look at our routes. Thanks. – wryrych Apr 04 '14 at 15:54