Edited at

form_forとform_tagの書き方の比較

More than 3 years have passed since last update.

Railsチュートリアル8章での表題の件

<!-- form_forの書き方 -->

form_for(モデルオブジェクト,{オプション})
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :password %>
<%= f.text_field :password %>

<%= f.submit 'Sign in', class: 'btn btn-large btn-primary' %>
<% end %>

<!-- form_tagの書き方(label, text_field使用) -->
form_tag(url, オプション)
<%= form_tag(sessions_path, method: "POST") do %>
<%= label :session, :email %>
<%= text_field :session, :email %>

<%= label :session, :password %>
<%= password_field :session, :password %>

<%= submit_tag 'Sign in', class: 'btn btn-large btn-primary' %>
<% end %>

<!-- form_tagの書き方2(label_tag, text_field_tag使用) -->

<%= form_tag(sessions_path, method: "POST") do %>
<%= label_tag 'Email' %>
<%= text_field_tag 'session[email]' %>

<%= label_tag 'Password' %>
<%= password_field_tag 'session[password]' %>

<%= submit_tag 'Sign in', class: 'btn btn-large btn-primary' %>
<% end %>