在ApplicationHelper中,我有一个名为finTime的方法。从自定义视图中调用助手方法Rails
def finTime(time)
end
在delayed_job的我有render_to_string功能
class ExportJob < Struct.new(:time1,:time2, :survey_id)
def perform
ac = ActionController::Base.new()
html = ac.render_to_string(:template => "pages/exportPdf.html.erb",:layout => "layouts/exportPdf",:formats => :html
end
end
在exportPdf.html.erb我调用该函数finTime
<%= finTime(f.created_at) %>
我得到了错误:“::的ActionView模板:错误:未定义方法'finTime'为#< #Class:0x6db8eb0>:0x8321928>“
所以我想问一下在这种情况下如何从exportPdf.html.erb调用finTime方法。我试图使用include和helper,但它不起作用。 谢谢!
对不起,我更新了finTime函数,它有参数。我认为蛇的情况不是问题,因为这个功能起作用。问题是该函数没有定义(不能调用该帮助函数)。ActionView :: Template:Error:未定义的方法'finTime'为#<#Class:0x6db8eb0>:0x8321928> – ZeroX
啊,对不起,蛇的情况绝对不是问题与它的工作与否,只是想说,这是惯例使用它的方法。将更新回答 – dax
感谢您的帮助。我可以通过使用PagesController.new.finTime现在:)调用finTime – ZeroX