Ruby on rails Rails 2.3.8邮件命名方法错误
Ruby on rails Rails 2.3.8邮件命名方法错误,ruby-on-rails,actionmailer,Ruby On Rails,Actionmailer,我用脚手架创建了一个简单的post控制器,如果有人访问索引页面,我想发送一封邮件。 我生成了一个TestMail类: class TestMail < ActionMailer::Base def welcome_email(sent_on) recipients 'lorem@ipsum.sa' from "My Awesome Site Notifications <notifications@example.com>"
我用脚手架创建了一个简单的post控制器,如果有人访问索引页面,我想发送一封邮件。
我生成了一个TestMail类:
class TestMail < ActionMailer::Base
def welcome_email(sent_on)
recipients 'lorem@ipsum.sa'
from "My Awesome Site Notifications <notifications@example.com>"
subject "Welcome to My Awesome Site"
sent_on Time.now
end
end
我得到了NoMethod错误:
NoMethodError in PostsController#index
undefined method `welcome_email' for TestMail:Class
怎么了?您使用的是Rails 3语法。 在Rails 2.3中,您需要使用
deliver\uu
或create\uu
# creates and delivers the email
TestMail.deliver_welcome_email(Time.now)
# creates the email
email = TestMail.create_welcome_email(Time.now)
# creates and delivers the email
TestMail.deliver_welcome_email(Time.now)
# creates the email
email = TestMail.create_welcome_email(Time.now)