Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 2.3.8邮件命名方法错误_Ruby On Rails_Actionmailer - Fatal编程技术网

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)