I am a beginner with 3 months of programming experience. The other day, I personally created an application ... It was when I was implementing a message posting form using ** "form_with" **. ..
View
= form_with model: @post, url: posts_path, method: :post, html:{ class: "post" } do |f|
= f.text_area :post
= f.submit "Post"
Oh, the view (screen) doesn't change even if you press the "Post" button, right? ??
Checking the model and path shouldn't be wrong ... However, it is not processed by the controller. ..
Yes, I was ** pretending to understand form_with and licking it completely **. (Of course I didn't feel like that) Because I've been studying form_for and form_tag so far, I thought that I could do the same thing just by changing the writing style.
If you give the answer immediately, form_with will ** automatically perform ajax processing (asynchronous communication) **! !! Of course, form_for and form_tag did not have such specifications.
View
//form_local at the end of with:I will describe true.
= form_with model: @post, url: posts_path, method: :post, html:{ class: "post" }, local: true do |f|
= f.text_area :post
= f.submit "Post"
After writing as above, you can post normally.
If you want to do ajax processing ** If ajax processing is not ** not ** ... local: true
That's it.
At a certain school or ○○ gate, I often study with form_for and form_tag, so Isn't there anyone other than me who falls into this situation? I thought, I wrote this time.
form_for and form_tag are very educational, so try studying once before getting used to form_with. I recommend it, but it's still a different thing, so it was around this time that I felt that form_with also needed to study hard.
Recommended Posts