Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to createRecord with belongsTo association with Ember.js & Rails?
    primarykey
    data
    text
    <p>I'm having trouble with a belongsTo association and sending a foreign key to my Rails controller with Ember.js and ember-data. My Ember.js controller will send the Project name to the Rails controller, but not the client_id value. In the Rails controller, params[:project][:client_id] comes through as nil.</p> <p>Help! Where am I going wrong?</p> <p><strong>Models:</strong></p> <pre><code>DA.Project = DS.Model.extend name: DS.attr('string') client: DS.belongsTo('DA.Client') DA.Client = DS.Model.extend name: DS.attr('string') projects: DS.hasMany('DA.Project') </code></pre> <p><strong>Controller:</strong></p> <pre><code>DA.ProjectsController = Em.ArrayController.extend createProject: (project) -&gt; @transaction = DA.store.transaction() p = @transaction.createRecord(DA.Project, project) validation_errors = p.validate() if validation_errors DA.displayError validation_errors else @transaction.commit() </code></pre> <p><strong>View:</strong></p> <pre><code>DA.ProjectsNew = Em.View.extend tagName: 'form' templateName: 'projects/new' init: -&gt; @_super() didInsertElement: -&gt; @_super() submit: (event) -&gt; event.preventDefault() project = {} project.name = @get('name') project.client = @get('client_id') DA.ProjectsController.createProject(project) </code></pre> <p><strong>Template:</strong></p> <pre><code>{{view Em.TextField valueBinding="view.name" placeholder="Project Name" tabindex="1"}} {{view Em.TextField valueBinding="view.client_id" placeholder="Client ID" tabindex="2"}} &lt;button type="submit"&gt;Create&lt;/button&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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