1
1

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+vue.jsでfields_forとv-forを同時に使う方法

Last updated at Posted at 2017-08-01
<div v-for='(index, user) in users'>
  <%= f.fields_for :users, User.new, child_index: '{{ index }}' do |user_form| %>
    <%= user_form.text_field :name, 'v-model': 'user.name' %>
  <% end %>
</div>

ポイント
v-forでindexを取り出す
child_indexにそのvueの変数であるindexが展開できるようにする
フィールドごとに、v-modelを設定する
空っぽのそのフィールド用のオブジェクトをfields_forに渡す

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?