【问题标题】:Protected render_to_string error受保护的 render_to_string 错误
【发布时间】:2015-08-11 13:49:16
【问题描述】:

我正在尝试使用PDFkit 导出resque 某些页面。但是当我尝试使用render_to_string 时遇到了几个错误。

错误:

protected method `render_to_string' called for #<ActionController::Base:0x5a65748 @real_format=nil>

使用时:

html = ActionController::Base.new.render_to_string(
        :template => route,
        :locals => locals,
        :layout => layout
)

还有这个:

undefined method `render_to_string' for Print:Module

使用时:

html = render_to_string(
        :template => route,
        :locals => locals,
        :layout => layout
)

我正在调用的方法是“return_generic_pdf_kit”并位于/lib/print.rb,我是从这样一个 resque 工作者那里调用它的:

kit = Print.return_generic_pdf_kit(url,
                             {
                                 :print_blank_eval => evaluator_type,
                                 :print_blank_prov => provider_type,
                                 :print_blank_appl => applicant_type,
                                 :form => form,
                                 :scholarship => scholarship
                             },
                             false, 1)

希望有人能帮我找到解决办法。

【问题讨论】:

    标签: ruby-on-rails ruby resque ruby-on-rails-2 pdfkit


    【解决方案1】:

    你可以使用它

    ac = ActionController::Base.new()
    ac.render_to_string(:template => route,
            :locals => locals,
            :layout => layout)
    

    【讨论】:

    • ac 变量会接收 html 吗?还是我应该这样做:html = ac.render_to_string(:template => route, :locals => locals, :layout => layout)
    • ` html = ac.render_to_string(:template => route, :locals => locals, :layout => layout)` 将工作,结果将在html 变量中
    • 这对我不起作用 - 为什么会这样?看起来一样
    猜你喜欢
    • 1970-01-01
    • 2011-02-02
    • 2016-11-24
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 2016-02-19
    相关资源
    最近更新 更多