Skip to content

Commit 897bc16

Browse files
justin808claude
andcommitted
Fix Rails version compatibility for content_security_policy_nonce
The content_security_policy_nonce helper has different signatures across Rails versions: - Rails 5.2-6.0: content_security_policy_nonce (no arguments) - Rails 6.1+: content_security_policy_nonce(directive) (optional argument) This change adds a try-catch to handle both versions gracefully. Fixes CI failures with "wrong number of arguments (given 1, expected 0)". 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 69651a5 commit 897bc16

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/react_on_rails/helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,16 @@ def wrap_console_script_with_nonce(console_script_code)
444444
return "" if console_script_code.blank?
445445

446446
# Get the CSP nonce if available (Rails 5.2+)
447-
nonce = content_security_policy_nonce(:script) if respond_to?(:content_security_policy_nonce)
447+
# Rails 5.2-6.0 use content_security_policy_nonce with no arguments
448+
# Rails 6.1+ accept an optional directive argument
449+
nonce = if respond_to?(:content_security_policy_nonce)
450+
begin
451+
content_security_policy_nonce(:script)
452+
rescue ArgumentError
453+
# Fallback for Rails versions that don't accept arguments
454+
content_security_policy_nonce
455+
end
456+
end
448457

449458
# Build the script tag with nonce if available
450459
script_options = { id: "consoleReplayLog" }

0 commit comments

Comments
 (0)