@ashishtajane wrote:
Lets say I have a post model with a title and a text field and two routes for the model -- new route and show route. I want to create a post from new route and then transition to show route.
This is my router file
this.route('post-new', { path: '/posts/new' }); this.route('post-show', { path: '/posts/:postId' });
and
submit
action inpost-new
controller, which creates post, is something like this.actions: { submit() { const { title, text } = this.getProperties('title', 'text'); let post = this.store.createRecord('post', { title: title, text: text }); post.save().then(() => { //success this.transitionToRoute('post-show', post); }, () => { //error }); } }
So I am expecting this to redirect from
http://localhost:4200/posts/new
to something likehttp://localhost:4200/posts/23
(assuming23
is id).
Thesave()
is successful and record is created on the backend (which is rails) and I also see thepost
record updated in browser (it now has an ID) using Ember Inspector. But the redirection is happening tohttp://localhost:4200/posts/undefined
.How can I make this to redirect to something like
http://localhost:4200/posts/23
after save ?Btw, The versions are:
ember cli : 2.3.0-beta.1
ember : 2.3.0
ember data : 2.3.3
Posts: 3
Participants: 2