I have Dish and Comment models as shown below in my Rails 5.1 API application - the repo code is here . I need help adding a new Comment to Dish .
Message
class Dish < ApplicationRecord has_many :comments end
A comment
class Comment < ApplicationRecord belongs_to :dish end
Mail Serializer (uses ActiveModel Seriazlier)
class DishSerializer < ActiveModel::Serializer attributes :id, :name, :image, :category, :label, :price, :featured, :description, :created_at has_many :comments end
Comment serializer
class CommentSerializer < ActiveModel::Serializer attributes :id, :rating, :comment, :author, :date def date object.created_at end end
Mail controller - rails scaffold by default
class DishesController < ApplicationController before_action :set_dish, only: [:show, :update, :destroy]
Comment controller - rails scaffold by default
class CommentsController < ApplicationController before_action :set_comment, only: [:show, :update, :destroy]
Question
When the user visits /dishes/:id and adds a comment to the plate through an external application (Angular 2), Comment clicks on the array of current comments, and I call PUT /dishes:id with a Dish object embedded in the existing comments and the new comment. However, the new Comment not saved by the rails - the error does not return, rather the Dish object is returned. However, I see Unpermitted parameters: :id, :created_at in the rails s console. How to get rails to save a new comment?
The page ( dishes/9 ), from where I add a comment to the dish, looks lower on the Angular client side. 
Rails Server Logs
On the side of the rails below is what I see in params - I see a new comment - {"author"=>"JANE7777", "rating"=>3, "comment"=>"COMMENT7777", "date"=>"2017-11-12T12:58:12.555Z"} there.
Started PUT "/dishes/9" for 127.0.0.1 at 2017-11-12 18:28:12 +0530 Processing by DishesController#update as HTML Parameters: {"id"=>"9", "name"=>"Uthappizza", "image"=>"images/uthappizza.png", "category"=>"mains", "label"=>"Hot", "price"=>"4.99", "featured"=>true, "description"=>"A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.", "created_at"=>"2017-11-01T04:30:09.407Z", "comments"=>[{"id"=>46, "rating"=>5, "comment"=>"Imagine all the eatables, living in conFusion!", "author"=>"John Lemon", "date"=>"2012-10-16T17:57:28.556Z"}, {"id"=>47, "rating"=>4, "comment"=>"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", "author"=>"Paul McVites", "date"=>"2014-09-05T17:57:28.556Z"}, {"id"=>48, "rating"=>3, "comment"=>"Eat it, just eat it!", "author"=>"Michael Jaikishan", "date"=>"2015-02-13T17:57:28.556Z"}, {"id"=>49, "rating"=>4, "comment"=>"Ultimate, Reaching for the stars!", "author"=>"Ringo Starry", "date"=>"2013-12-02T17:57:28.556Z"}, {"id"=>50, "rating"=>2, "comment"=>"It your birthday, we're gonna party!", "author"=>"25 Cent", "date"=>"2011-12-02T17:57:28.556Z"}, {"id"=>51, "rating"=>4, "comment"=>"great dish", "author"=>"Jogesh", "date"=>"2017-10-30T05:03:39.656Z"}, {"author"=>"JANE7777", "rating"=>3, "comment"=>"COMMENT7777", "date"=>"2017-11-12T12:58:12.555Z"}], "dish"=>{"id"=>"9", "name"=>"Uthappizza", "image"=>"images/uthappizza.png", "category"=>"mains", "label"=>"Hot", "price"=>"4.99", "featured"=>true, "description"=>"A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.", "created_at"=>"2017-11-01T04:30:09.407Z"}} Dish Load (1.0ms) SELECT "dishes".* FROM "dishes" WHERE "dishes"."id" = $1 LIMIT $2 [["id", 9], ["LIMIT", 1]] [25, 34] in C:/apps/railsApi/app/controllers/dishes_controller.rb 25: end 26: 27: # PATCH/PUT /dishes/1 28: def update 29: byebug => 30: if @dish.update(dish_params) 31: render json: @dish 32: else 33: render json: @dish.errors, status: :unprocessable_entity 34: end (byebug) params <ActionController::Parameters {"id"=>"9", "name"=>"Uthappizza", "image"=>"images/uthappizza.png", "category"=>"mains", "label"=>"Hot", "price"=>"4.99", "featured"=>true, "description"=>"A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.", "created_at"=>"2017-11-01T04:30:09.407Z", "comments"=>[{"id"=>46, "rating"=>5, "comment"=>"Imagine all the eatables, living in conFusion!", "author"=>"John Lemon", "date"=>"2012-10-16T17:57:28.556Z"}, {"id"=>47, "rating"=>4, "comment"=>"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", "author"=>"Paul McVites", "date"=>"2014-09-05T17:57:28.556Z"}, {"id"=>48, "rating"=>3, "comment"=>"Eat it, just eat it!", "author"=>"Michael Jaikishan", "date"=>"2015-02-13T17:57:28.556Z"}, {"id"=>49, "rating"=>4, "comment"=>"Ultimate, Reaching for the stars!", "author"=>"Ringo Starry", "date"=>"2013-12-02T17:57:28.556Z"}, {"id"=>50, "rating"=>2, "comment"=>"It your birthday, we're gonna party!", "author"=>"25 Cent", "date"=>"2011-12-02T17:57:28.556Z"}, {"id"=>51, "rating"=>4, "comment"=>"great dish", "author"=>"Jogesh", "date"=>"2017-10-30T05:03:39.656Z"}, {"author"=>"JANE7777", "rating"=>3, "comment"=>"COMMENT7777", "date"=>"2017-11-12T12:58:12.555Z"}], "controller"=>"dishes", "action"=>"update", "dish"=>{"id"=>9, "name"=>"Uthappizza", "image"=>"images/uthappizza.png", "category"=>"mains", "label"=>"Hot", "price"=>"4.99", "featured"=>true, "description"=>"A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.", "created_at"=>"2017-11-01T04:30:09.407Z"}} permitted: false> (byebug) c Unpermitted parameters: :id, :created_at (0.0ms) BEGIN (0.0ms) COMMIT [active_model_serializers] Comment Load (0.0ms) SELECT "comments".* FROM "comments" WHERE "comments"."dish_id" = $1 [["dish_id", 9]] [active_model_serializers] Rendered DishSerializer with ActiveModelSerializers::Adapter::Attributes (31.29ms) Completed 200 OK in 1901725ms (Views: 37.5ms | ActiveRecord: 5.0ms)
Client models
The Dish model has Comment[] as one of its members. When a new comment is added through the form, Comment clicks on the dish.comments array before submitting the Dish object to the Rails API.
Comment client-side model
export class Comment { rating: number; comment: string; author: string; date: string; }
Post client-side model
import { Comment } from './comment'; export class Dish { id: number; name: string; image: string; category: string; label: string; price: string; featured: boolean; description: string; comments: Comment[]; }