如何使用 Flash[:notice] 在使用备份 Gem 时进行通知



我正在使用备份 gem 来创建 pg DB 的备份,我们是否可以使用通知将闪存消息显示为备份完成而不是通过邮件通知。或任何其他定义自定义通知的方法。

当您从未呈现任何内容的控制器重定向时,Flash 消息通常会有所帮助。假设您要创建一个用户。现在,如果创建控制器没有呈现任何内容,而是重定向到主页,您可以在此处使用闪存消息。下面给出的是语法。

flash[:notice] = "User successfully created"

flash[:notice] = "Some error occured"

根据条件,下一页将显示闪烁消息。

谢谢

"

默认情况下,on_success、on_warning和on_failure通知始终为真。

notify_by Mail do |mail|
  mail.on_success = false
  mail.on_error = false
  mail.on_failure = false
  #flash[:notice] = 'Done...' or whatever
end

就像辛格说的,这些消息是让用户知道发生了什么。 使用备份 Gem,您无需通知用户有关备份的信息,除非它用于服务器管理员或类似的东西。

或者您可以覆盖通知

module Backup
  module Notifier
    class Mail < Base
      #....
      def notify!(status)
        name, send_log =
            case status
            when :success then [ 'Success', false ]
            when :warning then [ 'Warning', true  ]
            when :failure then [ 'Failure', true  ]
            end
        email = new_email
        email.subject = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
        email.body    = @template.result('notifier/mail/%s.erb' % status.to_s)
        if send_log
          email.convert_to_multipart
          email.attachments["#{@model.time}.#{@model.trigger}.log"] = {
            :mime_type => 'text/plain;',
            :content   => Logger.messages.join("n")
          }
        end
        email.deliver!
      end
    end
  end
end

https://github.com/meskyanichi/backup/blob/master/lib/backup/notifier/mail.rb

最新更新