我创建了两个邮件程序,其中一个不在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]日志:检查点开始:时间 app [postgres]:[13914-1] [WHITE]日志:检查点完成:写入0缓冲区(0.0%);添加0个事务日志文件,删除0个,再循环1个; write = 0.000 s,sync = 0.000 s,total = 0.007 s;同步文件= 0,最长= 0.000秒,平均值= 0.000秒
如果您有任何建议,请与我们联系。提前致谢。布赖恩
答案 0 :(得分:0)
问题的答案可能对其他人有帮助,也可能没有帮助。我定义了两个邮件程序类,一个在mailers / mailer.rb中,另一个在models / mailer中.rb
Rails 2.0没有使用邮件程序目录,显然我一直关注两个不同的来源,以获取有关如何设置它的信息。有可能其他人会遇到同样的问题。我删除了models / mailer.rb文件