Reputation: 4038
I'm currently building an Ember.js CRUD app and having issues with creating records using a shared template. I'm attempting to use the edit.hbs
file to also create records.
edit.hbs:
<div>
<label>Server name</label>
{{input value=name}}
<label>Operating system</label>
{{input value=operating_system}}
<label>Build stage</label>
{{input value=build_stage}}
</div>
<button {{action 'save'}}> ok </button>
serverCreateRoute.js.coffee:
Warthog.ServersCreateRoute = Ember.Route.extend
model: ->
Em.Object.create()
renderTemplate: ->
@render('server.edit', controller: 'serversCreate')
serverCreateController.js.coffee:
Warthog.ServersCreateController = Ember.ObjectController.extend({
actions: {
save: function() {
var newServer = this.store.createRecord('server', this.get('model'));
newServer.save();
this.transitionToRoute('server', newServer);
}
}
});
And this is the error upon clicking the 'ok' button in the form:
Uncaught TypeError: Object server has no method '_create'
Update
Ember.js version: 1.2.0
Ember Data version: 1.0.0-beta.2
Update
After playing with multiple combinations of Ember and Ember-data, I am now able to create records; however, newly created records do not persist after refreshing the page. Please note that upon creating a new record, I am redirected to /#/servers/null
- as expected, the Ember console shows these records' ids as null. Below is the output received after creating a record
POST http://testdomain.warthog.dev/servers 422 (Unprocessable Entity)
Update
Turns out there was a validates_presence_of
scope on my rails model. Removing that allows the records to persist, as well as updating Ember Data
Upvotes: 0
Views: 158
Reputation: 19128
This is a bug in a older version of ember data. To update your current version of ember data in rails asset pipline use the following in your Gemfile:
gem 'ember-data-source', '~> 1.0.0.beta.3'
Upvotes: 0