레일을 신입니다. 사용자는 알림을 아직 읽지 않은 경우에만 며칠 후에 이메일 알림을 받아야합니다. 나는 Action Mailer로 전자 메일 알림을 만들었지 만 시간 형식을 추가 한 후에는 작동하지 않습니다. 이메일은 5 일 후에도 사용자에게 전달되지 않습니다.레일스 이메일 통지 - 메일러
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
user_mailer.rb
class UserMailer < ApplicationMailer
def try_notif(notification, post, user)
@notification = notification
@post = post
@user = user
mail(to: @post.user.email, subject: 'New Notification')
end
end
어떤 오류가 있습니까? 'current_user.notifications.unread'가 날짜를 반환하는지 확인하십시오. 그렇지 않으면 비교가 실패합니다. – Sravan
예상되는 워크 플로우는 무엇입니까? 사용자가 하나의 특정 알림을 보는 순간 메일이 전송됩니다. 알림을 보지 않으면 이메일을 전혀받지 못합니다. 또한 알림을 이미보고있는 경우 알림에 대한 전자 메일을 보내는 요령은 무엇입니까? – spickermann
5.days.ago를 5.minutes.ago로 변경하려고 시도 할 때 이메일을받지 못했습니다. – Nsha