メールを送信するレールコードがあります。以下は私のコントローラーにあります:
def create
@users = Users.find(:all)
@sub = params[:sub]
@body = params[:body]
@index = 0
@users.each {|i| index++; Notifier.deliver_notification(@users.email_address, @sub, @body, @users.unsubscribe_link);}
flash[:notice] = "Mail was sent to " + @index + " people"
end
私のモデルには次のものがあります
class Notifier < ActionMailer::Base
def notification(email, sub, content, link)
recipients email
from "my_email@example.com"
subject sub
body :content => recipient, :link => link
end
end
これはすべてうまくいきます。私の質問は:
たとえば、ポプルの 1 つにメールを送信する際にエラーが発生した場合でも、私のフラッシュ メッセージには次のように表示されます。Mail was sent to X people
@index
メールが正常に送信された場合にのみ増加するようにするにはどうすればよいですか?