I'm assuming you placed the above code in an initializer or environment file.
To solve your problem, place the the code you pasted above into a module method and call it to load the config. Whenever the config_key changes call that method again and the config will reload:
module WickedPdfConfig
def self.load
if HeaderFooterDesign.first.config_key == true
WickedPdf.config = {
:layout => "pdf.html",
# ... rest of config code...
end
end
# load the config the first time (on boot)
WickedPdfConfig.load
Now you have a method you can call whenever config_key changes. For example if you have an admin controller where you change your settings:
class AdminController < ApplicationController
def update
if params[:header_footer_design][:config_key] != HeaderFooterDesign.first.config_key
HeaderFooterDesign.first.config_key = params[:header_footer_design][:config_key]
WickedPdfConfig.load
end
# ... more code maybe ...
end
end
Alternatively you can use Ruby's load
method. With this approach you don't need to wrap your config code in a module method but rather you'd load the file again. After updating your HeaderFooterDesign config you'd call:
load "path/to/config/file.rb"
And the code within that file would execute again and those settings would take effect.
Hope that helps.