使用Rails 3.在下面的第一段代码中,很难谷歌搜索此错误在尝试从我的邮件程序视图中呈现部分时的含义。
这是错误:
ActionView::Template::Error (undefined method `long_date' for #<#<Class:0x00000102452ab0>:0x00000102440b30>):
这是我的邮件程序视图(email_note.html.erb)
<div style="width:500px;">
<%= render :partial => "shared/note", :object => @note %>
</div>
这是我在我的部分中所做的调用,即抛出错误 &lt;%= long_date(note.created_at)%&gt;
当我从其他动作(例如我的notes_controller中的'show')给出部分@note对象时,long_date始终有效。这是方法
def long_date(date)
date.strftime('%A %b %e, %G')
end
这是我的ActionMailer类(地址和note_id是从我的notes_controller中的'email'动作发送的)
class UserMailer < ActionMailer::Base
default :from => "gminett@gmail.com"
def email_note(address,note_id)
@note = Note.find(note_id)
mail(:to => "#{address}", :subject => "Note from repository: #{@note.subject}")
end
end
对我而言rails(很可能是因为我的疏忽)并没有将我的@note对象解释为Note类,但我不知道如何修复它。非常感谢帮助。
答案 0 :(得分:1)
这是因为默认情况下,ActionMailer模板不共享ActionView所执行的相同帮助程序。如果您需要在邮件程序模板中使用帮助程序,请尝试在ActionMailer类中包含该模块:
include DateTimeHelper