我是铁杆新手。用户只有在尚未阅读通知的情况下才需要在几天后收到电子邮件通知。我已经使用Action Mailer创建了电子邮件通知,但在添加时间格式后它无法正常工作。 5天后,该电子邮件仍未提供给用户。
String input = "Hello, world!";
char[] forward = new char[input.length()];
char[] reverse = new char[input.length()];
getCharacters(input, forward, reverse);
// forward and reverse now contain the characters from input
user_mailer.rb
class NotificationsController < ApplicationController
def show
@notification = current_user.notifications.find_by_id(params[:id])
if current_user.notifications.unread > 5.days.ago
UserMailer.try_notif(@notification, @post, @user).deliver
end
end
def update
@notification = current_user.notifications.find_by_id(params[:id])
@notification.update(read: true)
redirect_to post_path(@notification.post)
end
def read_all
current_user.notifications.unread.update_all(read: true)
end
end
答案 0 :(得分:1)
我认为正确的代码是这样的: 需要使用当前时间检查每个通知
if current_user.notifications.unread
current_user.notifications.each do |notification|
if Time.current - notification.created_at > 120 #just checking in hours
#send reminder
end
end
end
或者可以尝试其他方式
@notifications = Notification.where(created_at: 5.days.ago..Time.current, unread: true)
if @notifications
@notifications.each do |notification|
#send notification
end
end