Created
September 28, 2013 13:17
-
-
Save csaunders/6741984 to your computer and use it in GitHub Desktop.
Why am I getting the error Uncaught TypeError: Object post has no method '_create' when trying to create a new post?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blember.Post = DS.Model.extend | |
title: DS.attr('string'), | |
isCompleted: DS.attr('boolean') | |
Blember.Post.FIXTURES = [ | |
{ | |
id: 1, | |
title: 'Hello World', | |
body: 'This is my first post', | |
isCompleted: true | |
}, | |
{ | |
id: 2, | |
title: 'Hello Ember', | |
body: 'This is my first post', | |
isCompleted: false | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blember.PostsController = Ember.ArrayController.extend | |
actions: | |
createPost: -> | |
title = @get('newTitle') | |
return if !title.trim() | |
post = @store.createRecord 'post', { | |
title: title, isCompleted: false | |
} | |
@set('newTitle', '') | |
post.save() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApplicationController | |
POSTS = [ | |
{title: "Hello World", body: "This is a body", is_completed: true}, | |
{title: "Another World", body: "Doodle, strudel", is_completed: false} | |
] | |
def index | |
respond_to do |format| | |
format.html | |
format.json { | |
render json: POSTS | |
} | |
end | |
end | |
def create | |
POSTS << params[:post] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment