File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 457457Remember that commands are invoked by a controller [ before action filter] ( https://guides.rubyonrails.org/action_controller_overview.html#filters ) .
458458That means controller rendering from inside a command halts the standard request cycle.
459459
460+ ### Commands Lifecycle
461+
462+ By default, commands are runned before existing ` before_action ` callbacks (as
463+ ` TurboBoost::Commands::Controller ` is automatically included in ` ActionController::Base ` ). You
464+ can configure this behavior to have more control over when commands are runned:
465+ ``` ruby
466+ # config/initializers/turbo_boost_commands.rb
467+ Rails .application.configure do
468+ config.turbo_boost_commands[:run_commands_before_controller_callbacks ] = false
469+ end
470+ ```
471+
472+ Then, you'll need to include ` TurboBoost::Commands::Controller ` manually where you want it:
473+
474+ ``` ruby
475+ class ApplicationController < ActionController ::Base
476+ before_action :action1
477+ before_action :action2
478+ before_action :action3
479+
480+ include TurboBoost ::Commands ::Controller
481+ end
482+ ```
483+
460484### Broadcasting Turbo Streams
461485
462486You can also broadcast Turbo Streams to subscribed users from a command.
Original file line number Diff line number Diff line change @@ -25,12 +25,19 @@ class Engine < ::Rails::Engine
2525 config . turbo_boost_commands [ :apply_client_state_overrides ] = false
2626 config . turbo_boost_commands [ :apply_server_state_overrides ] = false
2727
28+ # Choose whether we want to run commands before existing `before_action`
29+ # callacks
30+ config . turbo_boost_commands [ :run_commands_before_controller_callbacks ] = true
31+
2832 initializer "turbo_boost_commands.configuration" do
2933 Mime ::Type . register "text/vnd.turbo-boost.html" , :turbo_boost
3034
3135 ActiveSupport . on_load :action_controller_base do
3236 # `self` is ActionController::Base
33- include TurboBoost ::Commands ::Controller
37+ unless TurboBoost ::Commands . config [ :run_commands_before_controller_callbacks ] == false
38+ include TurboBoost ::Commands ::Controller
39+ end
40+
3441 helper TurboBoost ::Commands ::ApplicationHelper
3542 end
3643
You can’t perform that action at this time.
0 commit comments