LoginSignup
2
0

More than 3 years have passed since last update.

form_withの備忘録

Last updated at Posted at 2019-09-17

form_withはform_tag,form_forに取って変わられる存在。

form_withの基本は

html
<% form_with model: @model url: items_path,method: :post do |form| %>
  <% form.text_field :name,id="hoge" %>
  <% form.submit type: "hidden" %>
<% end %>

多分こんな感じ
formの部分のidとclassは自動付与。しかし、text_fieldの部分は手動で付与しなければならない

defaultでajax通信を行う使用。(remote: true)
なので、ajaxを使用しない時にはlocal: trueにしとく

別にmodelがいらない通信ならmodel optionを抜いてもいいし、model: modelの書き方でもok

paramsはこんな感じ

controller
<ActionController::Parameters {"utf8"=>"✓", "model"=>{"name"=>"22"}}>

modelインスタンスの中に入っている入れ子構造になる。paramsに直で入れるならインスタンス指定なして飛ばすといいかと。

2
0
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
2
0