フォローした際のエラーが解決できなくて困っています。
データがnilとなっていて、どうしてフォローした際にuserのデータが送れていないのかが分かりません。
参考にしたサイトとも同様なコードにしているのですが、分かりません。
・userモデル
def create_notification_follow!(current_user)
temp = Notification.where(["visitor_id = ? and visited_id = ? ",current_user.id, id])
if temp.blank?
notification = current_user.active_notifications.new(visited_id: id)
notification.save if notification.valid?
end
end
・relationshipコントローラー
def create
user = User.find(params[:follow_id])
current_user.follow(user)
# ここから通知機能
@user.create_notification_follow!(current_user)
# ここまで通知機能
flash[:success] = 'ユーザをフォローしました。'
redirect_to user
end
・notificationヘルパー
when "follow" then
tag.a(notification.visiter.name, href:users_user_path(@visiter), style:"font-weight: bold;")+"があなたをフォローしました"
参考サイト
https://qiita.com/bty__/items/2db1dd4fcd7945b980f7
バージョン
Ruby on Rails 6