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?

フォームに入力しても反映されない

Posted at

フォームに値を入力し、ボタンを押しても正常に動作しないことが発生した。

以下はフォーム入力し、ボタンを押下した後のログ

Started POST "/result" for ::1 at 2025-05-07 13:47:05 +0900
Processing by HomesController#result as TURBO_STREAM
  Parameters: {"authenticity_token"=>"[FILTERED]", "content"=>{"word"=>"おはようございます"}, "commit"=>"変換"}
  Rendering layout layouts/application.html.erb
  Rendering homes/index.html.erb within layouts/application
  Rendered homes/index.html.erb within layouts/application (Duration: 0.6ms | Allocations: 181)
  Rendered layout layouts/application.html.erb (Duration: 44.4ms | Allocations: 1277)
Completed 200 OK in 64ms (Views: 46.1ms | ActiveRecord: 0.0ms | Allocations: 1896)

原因は2行目の「result as TURBO_STREAM」の部分だった。

turbo_streamで画面を動かしたい場合、Turbo_stream形式のファイル(result.turbo_stream.erb)を用意する必要がある

⇒それが存在せず、結果として何も返せていない状態

解決策として、TurboStreamを無効化した。

<%= form_with url: "/result", method: :post, model: @content, data: { turbo: false } do |f| %>
  <%= f.text_area :word, placeholder: "ここに入力" %>
  <%= f.submit "変換" %>
<% end %>

data: { turbo: false }を付け足すことで、正常に動作した。

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?