Created
April 10, 2025 20:35
-
-
Save aseroff/9835b4c063fd767c54b171335cfb92ab to your computer and use it in GitHub Desktop.
Modifying an engine using the overrides directory / class_eval approach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/application.rb | |
require_relative "boot" | |
require "rails/all" | |
# Require the gems listed in Gemfile, including any gems | |
# you've limited to :test, :development, or :production. | |
Bundler.require(*Rails.groups) | |
module MyApp | |
class Application < Rails::Application | |
# ... | |
overrides = Rails.root.join('app', 'overrides') | |
Rails.autoloaders.main.ignore(overrides) | |
config.to_prepare do | |
Dir.glob("#{overrides}/**/*_override.rb").sort.each do |override| | |
load override | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/overrides/controllers/engine/application_controller_override.rb | |
Engine::ApplicationController.class_eval do | |
before_action :turn_off_csp_nonce_generation | |
content_security_policy do |policy| | |
policy.style_src :self, | |
:https, | |
:unsafe_inline | |
end | |
private | |
def turn_off_csp_nonce_generation | |
request.content_security_policy_nonce_directives = [] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment