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.redirectCalling
@redirecthandles the controller before/afterActions, then delegates toBatman.redirect.Batman.redirectcan take:"/posts")Batman.redirect(MyApp.Post)redirects to"/posts")Batman.redirect(thisPost)redirects to"/posts/#{thisPost.id}"*)Batman.redirect({controller: "posts", action: "index"})=>/postsBatman.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()=>/postsApp.get('routes').posts(6).path()=>/posts/6App.get('routes').posts().get(6).path()=>/posts/6App.get('routes').posts().get(6).get('edit').path()=>/posts/6/editYou could use one of those to get your url string, then pass the string to
@redirect.Hope this helps!