[Ruby] [Form has two arguments] rails, form_for / form_with arguments

less than 1 minute read

##【goal】

##【merit】 ■ Understanding of form ■ Understanding of association

##【Development environment】 ■ Mac OS catalina ■ Ruby on Rails (5.2.4.2) ■ Virtual Box:6.1 ■ Vagrant: 2.2.7

In the curriculum

form_for[@post, @comment]…..

Hmm?

Until now, form_for(@post)….

One argument, but why two? ? ?

The reason is that you have to pass two arguments.

In this case, it is association

Post: comment = 1 :many

Therefore, it is necessary to give a value to both post and comment…

So

Become ####form_for[@post, @comment]!!!!

that’s all, If you have any corrections, please FB! !!

[I want to read it together]

■ About comment function implementation https://qiita.com/tanaka-yu3/items/93d94b1ede8fb4be2981

■ About form_with https://qiita.com/tanaka-yu3/items/50f54f5d4f4b8dfe19f3

■ Method list https://qiita.com/tanaka-yu3/items/89abad875187494bec53