Skip to content

Commit

Permalink
Drop Redis for dev requirement (#675)
Browse files Browse the repository at this point in the history
Lean on web-console instead.
  • Loading branch information
dhh authored Sep 12, 2024
1 parent e9ed0a2 commit 1626765
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 43 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ This gem is automatically configured for applications made with Rails 7+ (unless
1. Add the `turbo-rails` gem to your Gemfile: `gem 'turbo-rails'`
2. Run `./bin/bundle install`
3. Run `./bin/rails turbo:install`
4. Run `./bin/rails turbo:install:redis` to change the development Action Cable adapter from Async (the default one) to Redis. The Async adapter does not support Turbo Stream broadcasting.

Running `turbo:install` will install through NPM or Bun if a JavaScript runtime is used in the application. Otherwise the asset pipeline version is used. To use the asset pipeline version, you must have `importmap-rails` installed first and listed higher in the Gemfile.

Expand All @@ -125,6 +124,8 @@ import "@hotwired/turbo-rails"

You can watch [the video introduction to Hotwire](https://hotwired.dev/#screencast), which focuses extensively on demonstrating Turbo in a Rails demo. Then you should familiarize yourself with [Turbo handbook](https://turbo.hotwired.dev/handbook/introduction) to understand Drive, Frames, and Streams in-depth. Finally, dive into the code documentation by starting with [`Turbo::FramesHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/frames_helper.rb), [`Turbo::StreamsHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/streams_helper.rb), [`Turbo::Streams::TagBuilder`](https://github.com/hotwired/turbo-rails/blob/main/app/models/turbo/streams/tag_builder.rb), and [`Turbo::Broadcastable`](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb).

Note that in development, the default Action Cable adapter is the single-process `async` adapter. This means that turbo updates are only broadcast within that same process. So you can't start `bin/rails console` and trigger Turbo broadcasts and expect them to show up in a browser connected to a server running in a separate `bin/dev` or `bin/rails server` process. Instead, you should use the web-console when needing to manaually trigger Turbo broadcasts inside the same process. Add "console" to any action or "<%= console %>" in any view to make the web console appear.

### RubyDoc Documentation

For the API documentation covering this gem's classes and packages, [visit the RubyDoc page](https://rubydoc.info/github/hotwired/turbo-rails/main).
Expand Down
20 changes: 0 additions & 20 deletions lib/install/turbo_needs_redis.rb

This file was deleted.

22 changes: 0 additions & 22 deletions lib/tasks/turbo_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@ module Turbo
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
end

def redis_installed?
Gem.win_platform? ?
system('where redis-server > NUL 2>&1') :
system('which redis-server > /dev/null')
end

def switch_on_redis_if_available
if redis_installed?
Rake::Task["turbo:install:redis"].invoke
else
puts "Run turbo:install:redis to switch on Redis and use it in development for turbo streams"
end
end

def using_bun?
Rails.root.join("bun.config.js").exist?
end
Expand All @@ -43,24 +29,16 @@ namespace :turbo do
desc "Install Turbo into the app with asset pipeline"
task :importmap do
Turbo::Tasks.run_turbo_install_template "turbo_with_importmap"
Turbo::Tasks.switch_on_redis_if_available
end

desc "Install Turbo into the app with webpacker"
task :node do
Turbo::Tasks.run_turbo_install_template "turbo_with_node"
Turbo::Tasks.switch_on_redis_if_available
end

desc "Install Turbo into the app with bun"
task :bun do
Turbo::Tasks.run_turbo_install_template "turbo_with_bun"
Turbo::Tasks.switch_on_redis_if_available
end

desc "Switch on Redis and use it in development"
task :redis do
Turbo::Tasks.run_turbo_install_template "turbo_needs_redis"
end
end
end

0 comments on commit 1626765

Please sign in to comment.