Use when you want to edit or add a specific model.
ruby:new.html.erb
form_for [argument] do |f|
~
end
Specify the model instance as an argument. (@Review etc.)
It will switch automatically when you post the form You can even save to DB
form_for is used when there is content you want to save in DB form_tag is used when it is not necessary to save it in DB
ruby:new.html.erb
form_for [@review] do |f|
f.text_field :name
end
with this
ruby:new.html.erb
<input id="review_name" name="review[name]" type="text" size="size set in review model">
Is synonymous with.
f.html tag: column name Described in. There are as many methods in form_for as there are html tags used for form.
https://qiita.com/jumpyoshim/items/ee5af466ef7959567174
https://pikawaka.com/rails/form_for
Recommended Posts