Skip to content

Instantly share code, notes, and snippets.

@aseroff
Created April 10, 2025 20:35
Show Gist options
  • Save aseroff/9835b4c063fd767c54b171335cfb92ab to your computer and use it in GitHub Desktop.
Save aseroff/9835b4c063fd767c54b171335cfb92ab to your computer and use it in GitHub Desktop.
Modifying an engine using the overrides directory / class_eval approach
# 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
# 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