0
0

More than 1 year has passed since last update.

form_withで送信ボタンを押しても動かないとき(同期通信)

Posted at

備忘録。
form_withで送信ボタンを作成したとき、ページの更新を行なうとテーブルに情報が残るし、けど更新しないとエラーもでないのに固まったままだった。

<div class="comment-form">
  <% if user_signed_in? %>
    <%= form_with model: [@item, @comment],local: true, id: "comment-form" do |f| %>
      <%= f.text_area :text , class: "comment-text"%>
      <%= f.submit "コメントをする", class: "comment-submit" %>
    <% end %>
  <% end %>
</div>
  <div id="comments">
  <h4><コメント一覧></h4>
    <% @item.comments.each do |comment| %>
      <div class="comment">
        <p class="user-info"><%= comment.user.nick_name %>: </p>
        <p><%= comment.text%></p>
      </div>
    <% end %>
</div>

結論、local: trueが抜けてました。今までlocal: trueくん、なんでいるの?君なんのためにそこにいるん?って思ってごめんなさい。君も大事な一員でした。
そうそう、local: trueが必要なのは同期通信の場合であって、非同期の場合はそうでないとか。
非同期実装の場合にまた書きます。

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