Ruby on rails 如何重新加载应用程序中的邪恶pdf.rb->;配置->;初始值设定项->;wicked_pdf.rb文件,无需在rails 2中重新启动服务器

Ruby on rails 如何重新加载应用程序中的邪恶pdf.rb->;配置->;初始值设定项->;wicked_pdf.rb文件,无需在rails 2中重新启动服务器,ruby-on-rails,wkhtmltopdf,ruby-on-rails-2,wicked-pdf,Ruby On Rails,Wkhtmltopdf,Ruby On Rails 2,Wicked Pdf,我在我的一个插件中进行了更改,以自定义pdf报告的页眉和页脚,因此我将文件wicked_pdf.rb的内容更改为 if HeaderFooterDesign.first.config_key == true WickedPdf.config = { :layout => "pdf.html", :margin => { :top=> 40, :bottom => 20, :left=> 30, :righ

我在我的一个
插件
中进行了更改,以自定义pdf报告的页眉和页脚,因此我将文件
wicked_pdf.rb
的内容更改为

if HeaderFooterDesign.first.config_key == true
  WickedPdf.config = {
    :layout => "pdf.html",
    :margin => {    :top=> 40,
      :bottom => 20,
      :left=> 30,
      :right => 30},
    :header => {:html => { :template=> "#{Rails.root}/vendor/plugins/globoschool_header_footer_designer/app/views/header_footer_designs/header.html.erb"}},
    :footer => {:html => { :template=> "#{Rails.root}/vendor/plugins/globoschool_header_footer_designer/app/views/header_footer_designs/footer.html.erb"}},
  }
else
  WickedPdf.config = {
    :layout => "pdf.html",
    :margin => {    :top=> 40,
      :bottom => 20,
      :left=> 30,
      :right => 30},
    :header => {:html => { :template=> 'layouts/pdf_header.html'}},
    :footer => {:html => { :template=> 'layouts/pdf_footer.html'}},
  }
end

每次更改
cofig_键
值时,我都需要重新启动服务器以获得效果,那么该如何操作呢?我不想每次都重新启动它,有什么帮助吗?

我假设您将上述代码放在初始值设定项或环境文件中

要解决您的问题,请将上面粘贴的代码放入模块方法中,并调用它来加载配置。每当config_键更改时,再次调用该方法,配置将重新加载:

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
现在您有了一个方法,可以在config_键更改时调用它。例如,如果您有一个管理员控制器,您可以在其中更改设置:

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
该文件中的代码将再次执行,这些设置将生效

希望有帮助

load "path/to/config/file.rb"