Ember dynamic segment is empty - ember.js

Please see http://jsfiddle.net/kt2Hz/
I have read the docs, api and browsed the source code of Ember. No luck!
The routes:
App.Router.map ->
#resource 'customers', path: 'my_customers', ->
#resource 'customer', path: '/:customer_id', ->
#route 'edit', path: '/my_edit'
App.CustomerEditRoute = Ember.Route.extend
setupController: (controller, model) ->
controller.set('content', model)
alert("inspect: #{Ember.inspect(model)}")
The alert output is "inspect: undefined"
And if I check the params, the object is empty:
App.CustomerEditRoute = Ember.Route.extend
model: (params) ->
alert("inspect: #{Ember.inspect(params)}")
The alert output is "inspect: {}"

the dynamic segment is only passed to the customer route, not the nested ones. so if you change the model hook in your CustomerEditRoute to
model: (params) ->
return this.modelFor("customer")
it should work.
(pretty much the same problem as here btw.)

Related

Ember update parent route's model after save record

I'm working on an Ember application with the intent of learning. I've setted on a UI where a parent route and template when first opened features a table of, for example, today’s items in the left hand column, and an area to the right that varies: details about an item, form for new/edit item, search, etc.
The trouble I have run into is that when I save a new item, the left hand table from the parent route is not updated with the new item. Having trouble finding a way of getting that route to refresh. The closet I came was by using pushObject on the model.
things template:
{{partial "things/table"}}
{{outlet}}
router.coffee
#resource "items", ->
#route "item", {path: "/:item_id"}
#route "new", {path: "/new"}
items route:
ItemsRoute = Ember.Route.extend(
model: -> #store.find 'item'
)
items new route:
ItemsNewRoute = Ember.Route.extend
renderTemplate: ->
this.render('items/form')
model: ->
#store.createRecord('item')
setupController: (controller, model)->
controller.set('model', model)
items new controller:
ItemsNewController = Ember.ObjectController.extend(
needs: 'items'
actions:
submit: -> #model.save().then(console.log('saved'(, console.log('failed'))
cancel: -> #transitionTo('items')
transitionAfterSave: (->
if #get('content.id')
#transitionToRoute('items.item', #get('content'))
).observes('content.id')
submit: -> #model.save().then(this.didSave.bind(this), console.log('failed'));
didSave: function() {
console.log('saved');
var route = this.container.lookup("route:items.index"); // use the name of route you want to refresh
route.refresh();
}

Setting the model in a nested route in Ember.js

I have a nested edit route:
#resource 'dashboard.communities.community', path: ':community_id', ->
#route 'edit'
In my route, I try to retrieve the model with modelFor:
CivicSourcing.DashboardCommunitiesCommunityEditRoute = Ember.Route.extend
model: (params, queryParams, transition) ->
#modelFor('community')
But this returns undefined. The parent route is successfully retrieving the community, though. Any idea what might be going on?
You're resource name is dashboard.communities.community not community
#modelFor('dashboard.communities.community')
Here's a similar example for colors.cool
http://emberjs.jsbin.com/OxIDiVU/442/edit

modelFor parent route stopped working as before

Given the following routes:
App.Router.map ->
#resource 'locations', path: '/:location_id', ->
#route 'events', path: '/events/:date'
App.LocationsEventsRoute = Ember.Route.extend
model: (params) ->
location_id = #modelFor('locations').get('id')
console.log location_id
Accessing "/#/gothenburg-se/events/2013-09-03", location_id returns null. This worked before v1.0. What changed and how do I fix this?
This is likely due to changes in Ember Data for 1.0.beta.1. You might want to check out the transition document.
https://github.com/emberjs/data/blob/master/TRANSITION.md
I think something like this would work for your route:
App.LocationsEventsRoute = Ember.Route.extend({
model : function(params){
// find returns a promise
var locProm = this.store.find('location',params.location_id);
// once the promise has resolved you can log the id
locProm.then(function(loc){
console.log( loc.get('id') );
});
// return the promise immediately and let Ember resolve it
return locProm;
}
});

Routing Links to parent routes in Ember JS

In my application I have the following route setup
Orders.Router.map ->
#resource "orders", path: '/', ->
#route 'new'
#route 'show', path: ':order_id'
#resource 'items', path: ':order_id/items', ->
#route 'new'
class Orders.ItemsNewRoute extends Ember.Route
model: (params) ->
Orders.Order.find params.order_id
Within my items.new route, I would like to have a link back to orders.show and am unable to find the best way of going about this.
I cannot find a way to bind my parameter from my URL to the linkTo helper. What would be the best way to go about this?
Ryan,
I'm not 100% sure I understand what your question is but linkTo is very simple to use.
{{#linkTo "orders.show" controller.content}}Show My Order{{/linkTo}}
The above code will send you to the orders.show route with the model being the content of your controller.
Steve
I don't think this is the best way to go about this, but I was able to mess about with the router a bit to make it more like this:
Orders.Router.map ->
#resource "orders", path: '/', ->
#route 'new'
#route 'show', path: ':order_id'
#resource 'items', path: ':order_id/items/new'
class Orders.OrdersRoute extends Ember.Route
model: ->
return Orders.Order.find()
class Orders.OrdersIndexRoute extends Ember.Route
model: ->
return Orders.Order.find()
class Orders.ItemsRoute extends Ember.Route
model: (params)->
return Orders.Item.createRecord
order: Orders.Order.find params.order_id
Then in my template I reference {{#linkTo 'orders.show' order}}
It seems that it was not able to grab a reference from the original :order_id wildcard.

nested routes mapping

This is the setup that I have
DS.RESTAdapter.configure 'plurals',
child: 'children'
App.Router.map ->
#resource 'people', ->
#resource 'person', path: ':person_id', ->
#route 'children'
App.PerosnChidlrenRoute = Ember.Route.extend
model: -> App.PerosnChidlren.find()
So, there is two problems here: first is that PersonChildren hitting /person_childrens instead of /people/:person_id/children.
And the second is incorrect pluralization as you can mention:)
Can you please explain how do I setup routing and pluralization correctly?
p.s. I've tried to put everything up in http://jsfiddle.net/UJkn3/1/