About form_for

Overview

Use when you want to edit or add a specific model.

How to use

ruby:new.html.erb


form_for [argument] do |f|
~
end

Specify the model instance as an argument. (@Review etc.)

merit

It will switch automatically when you post the form You can even save to DB

Proper use with form_tag

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

One case

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.

reference

https://qiita.com/jumpyoshim/items/ee5af466ef7959567174

https://pikawaka.com/rails/form_for

Recommended Posts

About form_for
About =
About method.invoke
About attr_accessor
About Hinemos
About inheritance
About params
About Docker
About Rails 6
About Spring ③
About enum
About polymorphism
About Optional
About hashes
About JitPack
About Dockerfile
About this ()
About devise
About encapsulation
About Docker
About JAVA_HOME
About active_hash
About static
About exceptions
About scope
[Maven] About Maven
About exception handling
About Java interface
[Java] About Java 12 features
About Rails routing
About cyclomatic complexity
About exception handling
About AsyncTask Generics
About array multiplication
[Java] About arrays
About ruby ​​form
[Swift] About generics
About Active Storage
About class inheritance.
About Spring AOP
About Ruby Hashes
About singular methods
About getter setter
About build tools
About MacinCloud introduction
[Note] About nil
About keyword arguments
Chew about API
[About double hash]
About installing Cocoapods
Something about java
Where about java
About HttpServlet () methods
About Java features
About ActiveRecord :: PendingMigrationError
About SIGNING_REGION: NoSuchFieldError
About the method
About standard classes
About spring AOP
About Ruby arrays
About Ruby inheritance