0
1

More than 3 years have passed since last update.

<table>内のform_withが作動しない・・・

Last updated at Posted at 2021-03-11

【ページ内リンク】

0.環境
1.事象
2.解決策
3.解決策2(turbolinks削除)

0.環境

・AWS
・Rails 5.2.4.5
・ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
・MySQL 5.7.31

1.事象

example.html.erb
<% team = Team.find(1) %>
<table>
  <%= form_with model: team do |f| %>
    <%= f.text_field :name %>
    <%= f.submit "登録" %>
  <% end %>
</table>

これで登録ボタンを押しても送信されない・・・
※ちなみにページ再読み込み(F5)すれば普通に作動した

ページ内リンクへ戻る

2.解決策

どうやら<table>内ではform_withは上手く作動しないみたい。なのでform_with<table>の外に出した

solution.html.erb
<% team = Team.find(1) %>
<%= form_with model: team do |f| %>
  <table>
    <%= f.text_field :name %>
    <%= f.submit %>
  </table>
<% end %>

これでうまく作動した

※ちなみに<thead><td>内にform_withを入れても問題なかった
※しかしそれらが<table>の入れ子になってたらやっぱりOUT

ページ内リンクへ戻る

3.解決策2(turbolinks削除)

application.html.erb
</head>の上にあるこの1行(いわゆるturbolinks)を削除する
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

turbolinksは、ページ遷移の際、いちいち読み込みをする必要を無くす役割。(ページ遷移しても更新ボタンが変化しない)
1.事象で書いた通り、F5をすれば作動したことから、試しにturbolinksを削除したら正常に作動した

ページ内リンクへ戻る

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