我的如下这段代码即使邮件发送不成功,也会创建一个新的 post,请问如何如果投送邮件失败,将这条 post.save rollback 呢?
def create
@post = post.new(post_params)
@post.user = current_user
if @post.save
begin
AppMailer.notify_on_new_post(current_user, @post).deliver
flash[:notice] = 'Post Created'
rescue Exception
flash[:error] = 'Oops, problems sending the mail'
end
redirect_to user_path(@post.user)
else
render :new
end
end