Reusing wizard for creating and updating records


I have a four step wizard process for creating a record. I am trying to figure out how to reuse the same templates and controllers for editing records. Ideally, I would prefer to have different routes for creating and editing, but I would be open to using the same routes as well. I have identified two ways that I might be able to do this.

One way would be to be to define new routes for editing the record and tell the routes to use the existing controllers and templates. Something like this:

Dfw.ActivityEditNameRoute = Em.Route.extend
  model: ->

  renderTemplate: (controller, model)->
    existingController = @controllerFor('')
    existingController.set('model', model)
    @render 'new_activity/name',
      controller: existingController
      outlet: main

The other way would be to try to componentize the wizard.

Is one of these two approaches preferred or is there another approach that I have not thought of?

EDIT: I did a bit more research and I see that someone asked a similar question about a year and a half ago (ancient history in the ember world). Sharing a controller / template for different routes The suggested solution was to do the renderTemplate and setupController technique in the route. Does this still hold true or are there newer techniques?


At this point, I think I’m too far down the rabbit hole of reusing the new_activity controllers and templates through my routes to attempt anything else. I will share a couple small tips I’ve learned along the way.

  1. Use actions to bubble up to the routers. If you need an action to behave a different ways have the controller action return true after the common action logic is complete or don’t even define the action in the controller. Define the action in the routes and have the routes implement the specific behavior. For example, in my case, this is a wizard, and I have to transitionTo specific routes.

  2. Considering that this is a wizard that needs to transition to specific routes, avoid the link-to helper and use an actions as actions can bubble up to the routes.

In general focus on handling the things specific to the route in the route, and remove that logic from the controllers and templates. If I think of more helpful nuggets, I’ll update this.