Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,30 @@ end
Remember that commands are invoked by a controller [before action filter](https://guides.rubyonrails.org/action_controller_overview.html#filters).
That means controller rendering from inside a command halts the standard request cycle.

### Commands Lifecycle

By default, commands are run before existing `before_action` callbacks (as
`TurboBoost::Commands::Controller` is automatically included in `ActionController::Base`). You
can configure this behavior to have more control over when commands are run:
```ruby
# config/initializers/turbo_boost_commands.rb
TurboBoost::Commands.config.tap do |config|
config[:run_commands_before_controller_callbacks] = false
end
```

Then, you'll need to include `TurboBoost::Commands::Controller` manually where you want it:

```ruby
class ApplicationController < ActionController::Base
before_action :action1
before_action :action2
before_action :action3

include TurboBoost::Commands::Controller
end
```

### Broadcasting Turbo Streams

You can also broadcast Turbo Streams to subscribed users from a command.
Expand Down
9 changes: 8 additions & 1 deletion lib/turbo_boost/commands/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ class Engine < ::Rails::Engine
config.turbo_boost_commands[:apply_client_state_overrides] = false
config.turbo_boost_commands[:apply_server_state_overrides] = false

# Choose whether we want to run commands before existing `before_action`
# callacks
config.turbo_boost_commands[:run_commands_before_controller_callbacks] = true

initializer "turbo_boost_commands.configuration" do
Mime::Type.register "text/vnd.turbo-boost.html", :turbo_boost

ActiveSupport.on_load :action_controller_base do
# `self` is ActionController::Base
include TurboBoost::Commands::Controller
unless TurboBoost::Commands.config[:run_commands_before_controller_callbacks] == false
include TurboBoost::Commands::Controller
end

helper TurboBoost::Commands::ApplicationHelper
end

Expand Down