Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails accepts_nested_attributes_for creating only

I have a Post model. I would like to let users create post comments while creating/updating a post by accepts_nested_attributes_for :comments. However, I don't want to let users update comments by nested attributes.

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

like image 501
Trantor Liu Avatar asked Jul 28 '14 14:07

Trantor Liu


1 Answers

Try to use something like this accepts_nested_attributes_for :comments, reject: :persisted? This will check, if Post object persisted or not. You also can replace persisted? with your custom method

like image 174
afilipko Avatar answered Nov 09 '22 23:11

afilipko