LoginSignup
11
9

More than 3 years have passed since last update.

【Rails】form_withのlocalオプション

Posted at

form_withとform_for

Rails5.1からform_forとform_tagが統合され、form_withに。
form_forとそんなに変わらない。

共通の特徴
- 自動でパスを選択してくれて、HTTPメソッドを指定する必要が無いこと
- コントローラーから渡された、ActiveRecordを継承するモデルのインスタンスが利用できること
- inputタグは用いないこと

使用例

hoge.html.erb
<%= form_with(model: @user, local: true) do |form| %>
  <%= form.text_field :name %>
  <%= form.submit "SEND" %>
<%= end %>

form_withではデフォルトの状態ではajaxでの通信がおこなわれる。
それをキャンセルするためのオプションんが local: true

11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9