LoginSignup
0
0

More than 3 years have passed since last update.

【formで引数が2つのもの】rails, form_for / form_with 引数

Posted at

【ゴール】

【メリット】

■ formの理解
■ アソシエーションの理解

【開発環境】

■ Mac OS catalina
■ Ruby on Rails (5.2.4.2)
■ Virtual Box:6.1
■ Vagrant: 2.2.7

カリキュラムにて

form_for[@post, @comment].....

ん?

今までは、
form_for(@post)....

引数が一つだったのに、なんで二つも???

理由は引数を2つ渡さないといけないから。

今回の場合はアソシエーションされている為

Post : comment = 1 : 多

なので、postのにも、commentにも値を与える必要がある、、、

なので、

form_for[@post, @comment]になる!!!!

以上、
修正箇所ございましたら、FBください!!

【合わせて読みたい】

■コメント機能実装について
https://qiita.com/tanaka-yu3/items/93d94b1ede8fb4be2981

■form_withについて
https://qiita.com/tanaka-yu3/items/50f54f5d4f4b8dfe19f3

■メソッド一覧
https://qiita.com/tanaka-yu3/items/89abad875187494bec53

0
0
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
0
0