Ruby on Railsのform_tagについてです。
よく使われるので基本だけ抑えていきます!
まず、form_tagとは?
ActionView::Helpersを継承したヘルパーです。
基本形は以下の通りです。
<%= form_tag([処理先], method: :[get または post], [そのたもろもろ]) do %> フォームの中身 <% end %>
index
基本の書き方7パターン
URL指定パターン(URL, method)
<%= form_tag('/home', method: :get) do %> フォームの中身 <% end %>
path指定パターン(path, method)
<%= form_tag(home_path, method: :get) do %> フォームの中身 <% end %>
controller, action指定パターン(controller, action, method)
<%= form_tag({:controller => 'home', :action => 'index'}, {:method => :post}) do %> フォームの中身 <% end %>
シンボルでも書けます。
<%= form_tag({controller: :home, action: :index}, {method: :post}) do %> フォームの中身 <% end %>
class, id指定パターン(class, id)
<%= form_tag(home_path, method: :post, class: "test_class",id: "test_id") do %> フォームの中身 <% end %>
ajax指定パターン(remote)
<%= form_tag(home_path, method: :post, remote: true) do %> フォームの中身 <% end %>
画像指定パターン(multipart)
<%= form_tag(home_path, method: :post, multipart: true) do %> フォームの中身 <% end %>
いろいろなパターンがあって一気に覚えられないかもしれないのですが
これだけ指定ができるので
いざ使うタイミングでギョッ!としないよう
事前知識でさらっと頭に入れておくといいですね(*^^*)
何か参考になれば幸いです(*^^*)