How to use the form_with method

【Overview】

1. Conclusion </ b>

2. How to use </ b>

  1. Conclusion

<%= form_with(model or URL, ) do |f| %>And use!

  1. How to use

I used it like this!

ruby:views/time/new.html.erb


<%= form_with(model: @time, local: true) do |f| %>

I put an instance variable in "model" with @time. If you specify the path with the url after the model, the method will automatically become a sorting function depending on the path, and you can also specify the action. Also, if you specify (****. Id) in the path, you can perform the action while pulling the id!

You can also specify class = "" and apply it to css!

|f|Can be applied to helper methods, form_The contents of with"f."You can put it in the one with! |f|Is like a variable, so it's okay if you unify it with an easy-to-use name!

f.label f.checkout f.password_field It can be applied to helper methods such as f.email_field!


Recommended Posts