I have an action:
{{action create target="controller"}}
which I have targeted to the bound controller (rather than the router) like this:
App.AddBoardController = Ember.Controller.extend
create: ->
App.store.createRecord App.Board, {title: @get "boardName"}
App.store.commit()
//TODO: Redirect to route
How do I redirect back to a route from the controller action?
In fact, this is not Ember idiomatic. From what I know, and what I have learnt from Tom Dale himself, here are some remarks about that code:
You should definitely put the action inside the router, and transitionTo accordingly.
Hope this will help.
UPDATE
First example (close to your sample)
In the appropriated route:
Refactored example
I would recommend having the following routes:
show
: displays an existing item,edit
: proposes to input item's fieldsInto the enclosing route, following event handlers:
createItem
: create a new record and transitionToedit
route, e.geditItem
: transitionToedit
routeInto the
edit
route, following event handlers:saveItem
: which will commit store and transitionToshow
route, e.gUse transitionToRoute('route') to redirect inside an Ember controller action:
EDIT: Keep reading, Mike's answer discusses some of the problems with this approach.
You can just call transitionTo directly on the router. If you are using defaults this looks like
App.router.transitionTo('route', context)
.