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?

hotwire-spark の導入

Last updated at Posted at 2025-11-06

rails8 hotwireを使っているプロジェクト
開発環境でホットリロードできるようにしたい
(アセット読み込みが毎回面倒なので)

この子を採用します。
https://github.com/hotwired/spark

以前はこちらを採用していましたが、設定が多い印象でした。
https://github.com/kirillplatonov/hotwire-livereload

まずは以下を追加して bundle install

group :development do
  gem "hotwire-spark"
end

これだけで動くみたいです。

画面を開いてエラーになる場合

エラー1

ActionView::Template::Error (The asset 'hotwire_spark.js' was not found in the load path.)
Caused by: Propshaft::MissingAssetError (The asset 'hotwire_spark.js' was not found in the load path.)

解決方法
コメントを戻す

config/application.rb
# require "action_cable/engine"
=>
require "action_cable/engine"

エラー2

Finished "/hotwire-spark" [WebSocket] for 172.23.0.1 at 2025-09-06 10:24:40 +0000
There was an exception - NoMethodError(undefined method 'fetch' for nil)

解決方法
config/cable.ymlを追加する
(他環境への影響があるかどうかは不明)

config/cable.yml
development:
  adapter: async

※slimの場合
以下を追加

config/environments/development.rb

Rails.application.configure do
  config.hotwire.spark.html_extensions += %w[ slim ]
end

画面が映って以下のようなログが出れば成功

[ActionCable] Broadcasting to hotwire_spark: {action: :reload_html, path: "/users/index.slim"}
Hotwire::Spark::Channel transmitting {"action" => "reload_html", "path" => "/users/index.slim"} (via streamed from hotwire_spark)
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?