English 中文(简体)
邮件:未定义的方法
原标题:ActionMailer: undefined method `recipients for

我正在撰写一份关于铁路3.2的测试,用于我的一个行动邮件——邀请邮件,但似乎发现“接收器”方法。

我的考验如下:

  describe "Invitation" do
    it "should send invitation email to user" do
    user = Factory :user

    email = InvitationMailer.invitation_email(user).deliver
    # Send the email, then test that it got queued
    assert !ActionMailer::Base.deliveries.empty?

    # Test the body of the sent email contains what we expect it to
    assert_equal [user.email], email.to
    assert_equal "You have been Invited!", email.subject

    end

我的邀请 邮件收看着:

class InvitationMailer < ActionMailer::Base
  default from: "[email protected]"

  def invitation_email(user)
    recipients  user.email
    from        "[email protected]"
    subject     "You have been Invited!"
    body        :user => user
  end

end

然而,我有以下错误:

 Failure/Error: email = InvitationEmail.invitation_email(user).deliver
 NoMethodError:
   undefined method `recipients  for #<InvitationMailer:0x007fca0b41f7f8>

有什么想法可以做到?

最佳回答

Here s an example from the Rails Guide for ActionMailer:

class UserMailer < ActionMailer::Base
  default :from => "[email protected]"

  def welcome_email(user)
    @user = user
    @url  = "http://example.com/login"
    mail(:to => user.email,
         :subject => "Welcome to My Awesome Site",
         :template_path =>  notifications ,
         :template_name =>  another )
  end
end

使你的法典更像这样看,可能更容易解决问题,因此,我首先要重新思考一下:

class InvitationMailer < ActionMailer::Base
  default from: "[email protected]"

  def hassle_email(user)
    @user = user
    mail(:to => user.email,
         :subject => "You have been Invited!")
  end
end

然后,请上<代码>:to,:subject and the @user 反对意见转告邮寄者,与任何其他观点一样。

Snce you re using recipients I wasn t sure if you were trying to send the email to multiple email addresses. If so, according to the ActionMailer documentation:

It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the :to key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas.

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签