初めてのレールです。ユーザーは通知をまだ読まなかった場合にのみ数日後に電子メール通知を受け取る必要があります。私は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
期待されるワークフローは何ですか?現時点では、ユーザーが1つの特定の通知を見た瞬間にメールが送信されます。彼が通知を見ないなら、彼はその電子メールをまったく受け取らないでしょう。さらに、すでに通知を見ている場合は、通知に関する電子メールを送信するのは何ですか? – spickermann
5.days.agoを5.minutes.agoに変更しようとしたときに電子メールを受信しませんでした。 – Nsha