Note that there are some explanatory texts on larger screens.

plurals
  1. POUrl contains 'undefined' instead of id after navigating back from 'edit' to 'show'
    primarykey
    data
    text
    <p>I read the <a href="http://emberjs.com/guides/outlets" rel="nofollow">Ember Application Structure</a> guide and now I trying to create a simple one page application with ember.js.</p> <p>My home page shows a sidebar containing a list of Post objects. When I click on a list-item, on the right of the sidebar I show a read-only version of the selected item. This version has a 'Edit' button, which makes it possible to edit the item. The edit version has a 'Cancel' link to switch back to the read-only version.</p> <p>I got this all working, however, when navigating back to the read-only version, the url in the address bar is not updated properly. When navigating back to my read-only version I expect the url to change from 'example.com/#posts/123/edit' to 'example.com/#posts/123', but instead I get ''example.com/#posts/undefined'.</p> <p>I tried to provide a context when calling transitionTo in the 'cancel' event, but that doesn't work.</p> <p>How can I navigate back to my read-only from while keeping the url pointing to the proper post (example.com/#posts/123)?</p> <p>Most of my code is identical to the example in the ember guide, my router and 'edit' related code is shown below:</p> <pre><code>App.EditPostView = Em.View.extend({ templateName: 'edit_post' }); App.Post = DS.Model.extend({ title: DS.attr('string'), body: DS.attr('string'), published: DS.attr('boolean') }); App.Router = Em.Router.extend({ enableLogging: true, location: 'hash', root: Em.Route.extend({ index: Em.Route.extend({ route: '/', redirectsTo: 'posts.index' }) }), posts: Em.Route.extend({ route: '/posts', # example.com/#posts showPost: Em.Route.transitionTo('posts.show'), editPost: Em.Route.transitionTo('posts.edit'), index: Em.Route.extend({ route: '/', connectOutlets: function(router) { router.get('applicationController').connectOutlet('posts', App.Post.find()); } }), show: Em.Route.extend({ route: '/:post_id', # example.com/#posts/123 connectOutlets: function(router, post) { router.get('postsController').connectOutlet('post', post); } }), edit: Em.Route.extend({ route: '/:post_id/edit', # example.com/#posts/123/edit connectOutlets: function(router, post) { router.get('postsController').connectOutlet({ viewClass: App.EditPostView, controller: router.get('postController'), context: post }); }, }), cancel: function(router, event) { router.transitionTo('show'); # Expect this to use 'example.com/#posts/123' but instead it shows 'example.com/#posts/undefined' } }) }); # edit_post.handlebars: &lt;form {{action save on="submit"}}&gt; ... {{view Em.TextField valueBinding="title"}} {{view Em.TextArea valueBinding="body"}} ... &lt;a {{action cancel}} class="btn"&gt;Cancel&lt;/a&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload