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 457
457
Remember that commands are invoked by a controller [ before action filter] ( https://guides.rubyonrails.org/action_controller_overview.html#filters ) .
458
458
That means controller rendering from inside a command halts the standard request cycle.
459
459
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
+ TurboBoost ::Commands .config.tap do |config |
468
+ config[: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
+
460
484
### Broadcasting Turbo Streams
461
485
462
486
You 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
25
25
config . turbo_boost_commands [ :apply_client_state_overrides ] = false
26
26
config . turbo_boost_commands [ :apply_server_state_overrides ] = false
27
27
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
+
28
32
initializer "turbo_boost_commands.configuration" do
29
33
Mime ::Type . register "text/vnd.turbo-boost.html" , :turbo_boost
30
34
31
35
ActiveSupport . on_load :action_controller_base do
32
36
# `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
+
34
41
helper TurboBoost ::Commands ::ApplicationHelper
35
42
end
36
43
You can’t perform that action at this time.
0 commit comments