0

Here is my form in template

<form>
  {{view Ember.TextArea valueBinding="comments" placeholder="Please type your comment here"}}
  <div class="form-footer">
   <button type="submit" class="btn pull-right btn-primary" tabindex="100" {{action saveIndianize}}>Save</button> 
  </div>
</form>

Here is my js model

App.Comment = DS.Model.extend({
    post_id: DS.attr('number'),
    user_id: DS.attr('number'),
    comments: DS.attr('string'),
    created_at: DS.attr('date'),
    job: DS.belongsTo('App.Post',{embedded:true}),
});

This is my serializer

attributes :id,:post_id,:user_id,:comments,:created_at

Here is my rails controller

@comment = Comment.new(user_id: params[:user_id],post_id: params[:post_id],comments: params[:comments])

When i submit the form throwing error as

Uncaught Error: assertion failed: Your server returned a hash with the key comments but you have no mapping for it

It is inserting into database with id(primary key), created_at and updated_at. But i couldn't see user_id, post_id and comments.

How can i solve it.

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113

2 Answers2

0

I suspect you have two problems here.

First, I think that user_id, post_id and comments are probably not being set due to mass assignment protection. If you're using Rails 4 you'll want to look into Strong Parameters and if you're on Rails 3 you'll want to investigate attr_accessible.

The error has to do with the JSON format that you are returning. You'll want to make sure that the JSON returns a main key of comment (singular), and not comments (plural).

{ "comment" : {...} }

Not :

{ "comments" : {...} }
Jeremy Green
  • 8,547
  • 1
  • 29
  • 33
0

Changes in my controller solved

@comment = Comment.new(user_id: params[:comments][:user_id],post_id: params[:comments][:post_id],comments: params[:comments][:comments])

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113