Railsでaccepts_nested_attributes :hoge, allow_destroy: true
なhas_many
関連を操作したい時にcollection_check_box
を使うことがよくありますが、諸事情でこれが使えない時に、ff.check_box :_destroy, {}, '0', '1'
と_destroy
属性のチェックボックスをvalue
の値を反転させて作ってやるとよい。
思いつけば単純なのですがハマって時間かかってしまったのでメモ。
More than 3 years have passed since last update.
[Rails] has_many関連を操作するためのフォームで collection_check_box が使えないときに _destroy 属性を使ってチェックボックスを作る時にはvalueを反転させてやると良い
Last updated at Posted at 2020-12-03
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme