Rails accepts_nested_attributes_for create-only

I have a Post model. I want users to create comments for comments when creating / updating the accepts_nested_attributes_for :comments message. However, I do not want users to update comments on nested attributes.

Is there a way to do something like accepts_nested_attributes_for :comments, create_only: true ?

+6
source share
1 answer

Try using something like accepts_nested_attributes_for: comments, reject :: persisted? This checks if the Post object is saved or not. Can you also replace the save? with your special method

+3
source

Source: https://habr.com/ru/post/972964/


All Articles