10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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

10
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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?