ruby-on-rails-5actionview

Rails 5: form_for vs form_with


Rails 5 has introduced new form helper method form_with.

How does it differs with form_for and when is it more appropriate to use?


Solution

  • This is really in preparation for rails 5.1 where only form_with should be used. It's meant to serve as a replacement for the two methods form_for and form_tag.

    form_for and form_tag in Rails were very similar, both allowed you to create a form tag but the first one uses model’s attributes to build create or update form, while the second one simply creates an HTML form tag with the passed URL as action.