0
0

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 1 year has passed since last update.

部分テンプレートのlocalオプションで変数指定

Posted at

##環境
Ruby 3.0.2
Rails 6.1.4.1

form_with以下を部分テンプレートにしたいため、
localオプションで変数fを指定する。
ここではlocalオプションで変数formfの2つ指定してることになる。

new.html.slim
= form_with model: @user_form, url: manage_user_path, local: true do |f|
  = render 'form', form: @user_form, f: f
edit.html.slim
= form_with model: @user_form, url: manage_users_path, local: true do |f|
  = render 'form', form: @user_form, f: f
_form.html.slim
= f.label :number, 'No.'
  = f.number_field :number
  
= f.label :name, '名前'
  = f.text_field :name

= f.submit '保存する'

##参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?