What is the difference between form_for and form_tag?

Asked

Viewed 284 times

1

What’s the difference between form_for and form_tag in the construction of forms since the final result is apparently the same?

In which situation choose one or the other?

1 answer

1

form_for you use for a specific model, ex

<% form_for @user do |f|

<%= f.text_field :nome %>
<%= f.email_field :email %>
<%= f.submit %>
<% end %>

Form tag vc uses to create simple Forms

<%= form_tag '/search' do %>
  <%= text_field_tag "q" %>
<% end %>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.