form_for and form_tag, when to use which one?

后端 未结 2 1511
失恋的感觉
失恋的感觉 2020-12-28 19:07

I am reading a Rails book and so far it has been using form_for to create the forms. In the new chapter that it is building a login page for users, it is using

2条回答
  •  死守一世寂寞
    2020-12-28 19:37

    In most cases when you are sending data to your database with a model, in methods like create, update, destroy. For this type of action you can use form_for.

    Instead form_tag only create a simply form html, for example, a search:

     <%= form_tag("/search", :method => "get") do %>
       <%= label_tag(:q, "Search for:") %>
       <%= text_field_tag(:q) %>
       <%= submit_tag("Search") %>
    <% end %>
    

提交回复
热议问题