Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Jul 29, 2014

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.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus