LoginSignup
2
2

More than 5 years have passed since last update.

accepts_nested_attributes_for で ["can't be blank"] と言われたら

Last updated at Posted at 2015-10-23

inverse_ofで解決できる
いや (追記)rejet_ifの可能性の方が大きいかも
Rails - accepts_nested_attributes_for を使った入れ子のformが罠だらけな気がする - Qiita

参考URLとその重要部分を引用する
(最も重要である回答のソースはSOを見てもらえばよいと思うので引用しない)

ruby on rails - Trouble with accepts_nested_attributes_for on validating foreign key - Stack Overflow

can't be blank while using accepts_nested_attributes_for (Rails 4) - Stack Overflow

Try removing contact_id to test if it will accept or not. If it does accept, it means you're not passing the contact_id through your params to the model

accepts_nested_attributes_for with Has-Many-Through Relations

It seemed Rails was not setting the notice attribute on the EntityRole before attempting to save it, triggering the validation errors. This is a bit surprising as other has_many relations (omitted in this blog post) should have the same save mechanics and were working just fine.


When you use collection= assignment with a has-many-through (as accepts_nested_attributes_for does), you have to specify inverse_of for Rails to save everything correctly.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2