1

我创建了两个邮件程序,其中一个不在 Heroku 的生产环境中工作。另一个邮件程序已经过测试并且可以正常工作,所以我知道使用 sendgrid 的电子邮件配置正在工作。

我有一个邀请模型:

class Invitation < ActiveRecord::Base
  attr_accessible :recipient_email, :sender_id, :sent_at, :token
  belongs_to :sender, :class_name => 'User'
  has_one :recipient, :class_name => 'User'
  validates_presence_of :recipient_email
  validate :recipient_is_not_registered
  validate :sender_has_invitations, :if => :sender

  before_create :generate_token
  before_create :decrement_sender_count, :if => :sender 
  after_create do |invitation|
  Mailer.delay.deliver_invitation(invitation)
  end

  private

  def recipient_is_not_registered
    errors.add :recipient_email, 'is already registered' if User.find_by_email(recipient_email)
  end

  def sender_has_invitations
    unless sender.invitation_limit > 0
      errors.add_to_base 'You have reached your limit of invitations to send.'
    end
  end

  def generate_token
    self.token = Digest::SHA1.hexdigest([Time.now, rand].join)
  end

  def decrement_sender_count
    sender.decrement! :invitation_limit
  end
end

邮递员:

class Mailer < ActionMailer::Base
  helper ActionView::Helpers::UrlHelper
 default from: "noreply@lumeo.com"

 def invitation(invite)
   @invitation = invite

   mail to: invitation.recipient_email, subject: "Invitaiton"
 end
end

一个文本文件:

You are invited to join our beta!
<%= link_to 'Sign Up', signup_url(@invite.token) %>

还有一个观点:

<div class="breadcrumbs span12 row">
    <p>
        <%= link_to "contests", contests_path %> > send invitation
    </p>
</div>
<div class="span12">
    <div class = "span6 offset2 pull-left">
        <div class="title">
            <h1>Invite Friends</h1>
        </div>
        <%= simple_form_for @invitation do |f| %>
            <fieldset class="edit well">
                <p></p>
                <p><%= f.input :recipient_email, :label => "Friend's email address" %></p>
            </fieldset>
            <div class="form-actions">
                  <%= f.submit 'Send Invite', :class => 'btn btn-primary pull-right btn-large m5' %>
            </div>
        <% end %>
    </div>
    <div class = "well pull-right span2">
        <% if current_user.invitation_limit > 0 %>
        <p>
            Welcome <%= current_user.name %>, 
            you have <%= current_user.invitation_limit %> invitations left</p>
        <% else %>
        <% end %>
    </div>

</div>

这是heroku的日志文件:

heroku[router]: GET www.lumeo.com/invitations/new dyno=web.1 queue=0 wait=0ms service=85ms status=200 bytes=4922
app[worker.1]: [Worker(host:881b0507-883f-43b1-b3aa-7cfddc9c17fa pid:2)] Class#invitation failed with ArgumentError: wrong number of arguments (0 for 1) - 0 failed attempts
app[worker.1]: [Worker(host:881b0507-883f-43b1-b3aa-7cfddc9c17fa pid:2)] Class#invitation failed with ArgumentError: wrong number of arguments (0 for 1) - 1 failed attempts
app[worker.1]: [Worker(host:881b0507-883f-43b1-b3aa-7cfddc9c17fa pid:2)] 2 jobs processed at 4.3239 j/s, 2 failed ...
app[worker.1]: [Worker(host:881b0507-883f-43b1-b3aa-7cfddc9c17fa pid:2)] Class#invitation failed with ArgumentError: wrong number of arguments (0 for 1) - 2 failed attempts
app[worker.1]: [Worker(host:881b0507-883f-43b1-b3aa-7cfddc9c17fa pid:2)] Class#invitation failed with ArgumentError: wrong number of arguments (0 for 1) - 3 failed attempts
app[worker.1]: [Worker(host:881b0507-883f-43b1-b3aa-7cfddc9c17fa pid:2)] 2 jobs processed at 11.4575 j/s, 2 failed ...

app[postgres]:[13913-1] [WHITE] LOG:检查点开始:时间 app[postgres]:[13914-1] [WHITE] LOG:检查点完成:写入 0 个缓冲区(0.0%);添加了 0 个事务日志文件,删除了 0 个,回收了 1 个;写入=0.000 秒,同步=0.000 秒,总计=0.007 秒;同步文件=0,最长=0.000 秒,平均=0.000 秒

如果您有任何建议,请告诉我。提前致谢。布赖恩

4

1 回答 1

0

该问题的答案可能对其他人有帮助,也可能对其没有帮助。我定义了两个邮件程序类,一个在 mailers/mailer.rb 中,另一个在 models/mailer.rb

Rails 2.0 显然没有使用 mailers 目录,我一直在关注两个不同的来源以获取有关如何设置它的信息。其他人可能会遇到同样的问题,所以就是这样。我删除了 models/mailer.rb 文件

于 2012-09-30T05:53:14.850 回答