Ember.js Select for association with selected option
I was attempting to rebuild a Rails form in Ember. The form requires a select for an association, in this case a project belongs to client, so the select needs to present an options list of clients, with a selected option based on the project model’s client_id. Had the damnedest time figuring this out. This is how I accomplished it in the end.
Route file:
App.ProjectsNewRoute = Ember.Route.extend(
setupController: (controller, model)->
controller.set('model', model)
controller.set('clients', @store.find('client'))
)
Template file:
{{view Ember.Select
content=clients
optionValuePath="content.id"
optionLabelPath="content.name"
selection=client
class="form-control"}}
I am available for Ember consulting work – get in touch to learn more.