使用 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>
这是我在部分中进行的调用,它引发了错误 <%= long_date(note.created_at) %>
当我从其他操作(例如我的 notes_controller 中的“显示”)中给出部分 @note 对象时,long_date 一直有效。这是方法
def long_date(date)
date.strftime('%A %b %e, %G')
end
这是我的 ActionMailer 类(地址和 note_id 是从我的 notes_controller 中的“电子邮件”操作发送的)
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 类,但我不知道如何解决它。非常感谢您的帮助。