I am trying to redirect to an index action after save, and can't figure out the proper NamedRouteQuery. I have tried:
@routes.posts.index
- `App.get('routes.posts.index')
- `App.get('routes.posts').index
- `App.get('routes.posts')
- `App.get('routes').posts
etc, but in the end the only thing that works is @redirect '/posts'
. Is the string version the only option for index
actions?
There are a few ways to get this done.
Passing params to
Batman.redirect
Calling
@redirect
handles the controller before/afterActions, then delegates toBatman.redirect
.Batman.redirect
can take:"/posts"
)Batman.redirect(MyApp.Post)
redirects to"/posts"
)Batman.redirect(thisPost)
redirects to"/posts/#{thisPost.id}"
*)Batman.redirect({controller: "posts", action: "index"})
=>/posts
Batman.redirect({controller: "posts", action: "edit", id: 6})
=>/posts/6/edit
* Actually calls
record.toParam?() || record.get('id')
to get the paramSo, you could use
@redirect({controller: "posts", action: "index"})
or@redirect(App.Post)
to redirect to the index action.Using a NamedRouteQuery
I'm not great with NamedRouteQuery, but here are some examples anyways:
App.get('routes').posts().path()
=>/posts
App.get('routes').posts(6).path()
=>/posts/6
App.get('routes').posts().get(6).path()
=>/posts/6
App.get('routes').posts().get(6).get('edit').path()
=>/posts/6/edit
You could use one of those to get your url string, then pass the string to
@redirect
.Hope this helps!