# Model と画面上の form が1対1で一致しない場合、どのように実装するのが綺麗なのか？

**URL:** <https://discourse.clean-rails.org/t/model-form-1-1/14>\
**Category:** Uncategorized\
**Created:** [2018 年 3 月 19 日午後 2:24 UTC](https://discourse.clean-rails.org/t/model-form-1-1/14 "2018-03-19T14:24:33Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![joker1007](https://discourse.clean-rails.org/user_avatar/discourse.clean-rails.org/joker1007/32/902_2.png) [@joker1007](https://discourse.clean-rails.org/u/joker1007)\
**Post date:** [2018 年 4 月 16 日午前 7:48 UTC](https://discourse.clean-rails.org/t/model-form-1-1/14/8 "2018-04-16T07:48:10Z")

</div>

accepts\_nested\_attributesは滅びるべきAPIだと思ってるので、自分なら絶対使いません。  
大きな理由は2点かな。

- あれはActiveRecordのAPIでPOROに使えないので、ARのカラム構造と現実が合わなくなった時や付随する処理でPOROが必要になった時に調整で苦労する可能性が高い
- ReactやVueの様なJSON構造と表示のbindingと相性が悪い(名前付けのルールとかdestroyフラグとか)
- この手の複数選択系のフォームはまともなUIで作るならJSでの項目の増減や個別の編集フォーム等はほぼ必須で、今時そういうUIをRailsのform helperをベースに作ることはほぼ無いので、記述削減のメリットが無い。

基本はFormオブジェクトで、シンプルに一要素だけでマッピング可能であるならtkawaさんのスタイルも使いそうです。

---

_[View the full topic](https://discourse.clean-rails.org/t/model-form-1-1/14)._
