[Meaning of model: of form_with]

Opinion of model: described in form_with

I didn't understand it well, but I finally understood the meaning, so I will describe it as an output.


The image above describes the code to display the form for posting a comment from the detail screen of the tweet. I couldn't understand why I used model: @tweet and @comment following form_with, but I solved it, so I will explain the reason below.

1st point

In this case, it is a situation where you comment on a tweet, and since the comment is linked to one tweet, you can not specify the comment alone as the destination of the form, so it is linked to @tweet, @comment The reason is that the destination is specified as a set with.

2nd point

The description itself @tweet, @comment specifies routing. What does that mean? Look at the image below.


In this case, I want to create a comment, so the action I want to activate is the create action of the comments controller. And if you look at the prefix item on the far left, you will see a path called tweet_comments. The bottom line is that you have to specify this routing if you want to submit a form and make a comment.

The second reason is that model: [@tweet, @ comment] specifies that routing.

that's all.

Recommended Posts

[Meaning of model: of form_with]
Meaning of final
About form. ○○ of form_with
Form part attributes of form_with
Consideration of Routing of form_with helper method
Meaning of writing an import statement
A simple example of an MVC model