Understand form_with
■ Rails recommendation is "form_with" ■ It's not that difficult, so you should remember
■ Mac OS catalina ■ Ruby on Rails (5.2.4.2) ■ Virtual Box:6.1 ■ Vagrant: 2.2.7
■form_for There is a model. Used for data you want to save in DB
■form_tag No model Used when performing POST processing
■form_with Both swords A convenient method that combines the above two functions
Model name: Book Column name ①: name Column name ②: title
books/index.html.erb
<% form_with model:Book do |f| %> #model postscript
<%= f.text_field :name %>
<%= f.text_area :text %>
<%= f.submit %>
<% end %>
hoge.html.erb
<%= form_with url:hoge_path do |f| %> #Add path name
<%= f.text_area :name %>
<%= f.text_area :question %>
<%= f.submit %>
<% end %>
that's all.
** If there is a model, specify the model name If there is no model, specify by path name **
I also escaped from using it It was really easy, so please use it if you like.
Recommended Posts