Ruby on rails Rails/ActionMailer/PostmarkRails多次发送相同的电子邮件
我有个问题。我的邮递员发送相同的电子邮件4次。我敢肯定我只打过一次电话。原因可能是什么 在Ruby 1.9.2和Unicorn上运行Rails 3.0.7,如果有必要的话 这是邮递员:Ruby on rails Rails/ActionMailer/PostmarkRails多次发送相同的电子邮件,ruby-on-rails,email,postmark,Ruby On Rails,Email,Postmark,我有个问题。我的邮递员发送相同的电子邮件4次。我敢肯定我只打过一次电话。原因可能是什么 在Ruby 1.9.2和Unicorn上运行Rails 3.0.7,如果有必要的话 这是邮递员: class NotificationMailer < ActionMailer::Base default :from => "herald@artistsnclients.com" def order_new(user, order) @user = user @order
class NotificationMailer < ActionMailer::Base
default :from => "herald@artistsnclients.com"
def order_new(user, order)
@user = user
@order = order
mail( :to => "#{user.name} <#{user.email}>", :subject => "You have one new order to review (##{order.id})" )
end
end
调用邮件程序的是模型通知中的回调:
class Notification < ActiveRecord::Base
attr_accessible :read, :user_id, :happening_type, :happening_id, :happening_status
enum_attr :happening_status, %w(new approved rejected cancelled payed completed accepted new_post)
belongs_to :user
belongs_to :happening, :polymorphic => true
after_create :send_email
private
def send_email
# Send e-mail here
if [:new, :approved, :rejected, :cancelled, :payed, :completed, :accepted].include? self.happening_status
right_mailer = NotificationMailer.method("order_#{self.happening_status}".to_sym)
right_mailer.call(self.user, self.happening).deliver
elsif [:new_post].include? self.happening_status
NotificationMailer.note_new(self.user, self.happening).deliver
end
end
end
通知对象是从注释模型中的回调创建的:
class Note < ActiveRecord::Base
...
after_create :notify_artist
private
def notify_artist
self.notifications.create :read => false, :happening_status => :new, :user_id => self.artist_id
end
end
此外,以下是属于从中创建通知模型的控制器的日志部分:
Started POST "/notes" for 178.8.127.86 at 2011-07-15 18:03:45 +0000
Processing by NotesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8UhgV74SUZibcrowriqQZAketiALnkpHMhu0bkuZ4VQ=", "note"=>{"content"=>"Okaaay, *will do*", "order_id"=>"1"}, "commit"=>"Reply"}
[1m[36mUser Load (0.1ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1[0m
[1m[35mSQL (0.1ms)[0m BEGIN
[1m[36mSQL (0.5ms)[0m [1mdescribe `notes`[0m
[1m[35mAREL (0.3ms)[0m INSERT INTO `notes` (`user_id`, `order_id`, `content`, `created_at`, `updated_at`) VALUES (1, 1, 'Okaaay, *will do*', '2011-07-15 18:03:45', '2011-07-15 18:03:45')
[1m[36mOrder Load (0.1ms)[0m [1mSELECT `orders`.* FROM `orders` WHERE `orders`.`id` = 1 LIMIT 1[0m
[1m[35mNotification Load (0.5ms)[0m SELECT `notifications`.* FROM `notifications` WHERE (`notifications`.happening_id = 12 AND `notifications`.happening_type = 'Note') LIMIT 1
[1m[36mSQL (0.9ms)[0m [1mdescribe `notifications`[0m
[1m[35mAREL (0.3ms)[0m INSERT INTO `notifications` (`read`, `user_id`, `happening_id`, `happening_type`, `created_at`, `updated_at`, `happening_status`) VALUES (0, 2, 12, 'Note', '2011-07-15 18:03:45', '2011-07-15 18:03:45', 'new_post')
[1m[36mUser Load (0.2ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1[0m
[1m[35mNote Load (0.3ms)[0m SELECT `notes`.* FROM `notes` WHERE `notes`.`id` = 12 LIMIT 1
Rendered notification_mailer/note_new.html.haml (3.6ms)
Sent mail to [MY E-MAIL] (2362ms)
Date: Fri, 15 Jul 2011 18:03:46 +0000
From: herald@artistsnclients.com
To: Dummy <[MY E-MAIL]>
Message-ID: <4e208102724f_55c11225a4584d7@artistsnclients.mail>
Subject: New message in order #1
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hello Dummy,</p>
<p>There is a new message in your order #1.</p>
<blockquote>
Okaaay, *will do*
</blockquote>
<hr>
<p>
With lots and lots of love,
<br>
Artists&Clients Staff
</p>
[1m[36mSQL (564.1ms)[0m [1mCOMMIT[0m
Redirected to http://dev.artistsnclients.com/orders/1
Completed 302 Found in 3623ms
请尝试名为0.9.8的较新版本的gem,我认为我们已成功修复了该漏洞:
如果有帮助,请告诉我。原因是满月和灌木丛中的三头牛。我的意思是先显示代码和日志。好的,是的,对不起。我不确定要显示代码的哪一部分,并认为可能是某种版本不兼容,因为我在另一台装有Ruby 1.8和Passenger的服务器上运行它,它只发送了一封电子邮件,正如它应该和现在的日志文件一样,我们可以在其中看到四封传出的电子邮件。我添加了log/development.log中的摘录,该摘录对应于触发它的控制器。下一个条目已经是一个不同的控制器,所以是的,我只看到模板被渲染一次。这是否意味着它只是为其他3封电子邮件缓存,还是意味着窃听发生在邮戳rails gem中?好的,这里只有一封传出的电子邮件,而不是四封