Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top