开发者

Rails 2.3.8 mail NoMethod error

I created a simple post controller with scaffolding and I want send a mail if someone visiting the index page.

I generated a TestMail class:

class TestMail < ActionMailer::Base

 def welcome_email(sent_on)
    recipients    'lo开发者_运维百科rem@ipsum.sa'
    from          "My Awesome Site Notifications <notifications@example.com>"
    subject       "Welcome to My Awesome Site"
    sent_on       Time.now

  end

end

But if I call this method in Post controller

asd=TestMail.welcome_email(Time.now)

I got NoMethod error:

NoMethodError in PostsController#index

undefined method `welcome_email' for TestMail:Class

What's wrong?


You're using the Rails 3 syntax. With Rails 2.3, you need to use deliver_ or create_.

# creates and delivers the email
TestMail.deliver_welcome_email(Time.now)

# creates the email
email = TestMail.create_welcome_email(Time.now)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜