UserNotification belongs_to用戶和用戶has_many UserNotification。Rails - 我可以訪問控制檯中的對象,但不能訪問應用程序
我想通過用戶訪問通知。
User.find(31).user_notifications
它返回以下用戶::
<Employer id: 31, email: "[email protected]", ...>
上面的代碼是正確的(用戶的類型可以是「僱主」或「自由職業者」的,我相信這一點,如果我在控制檯中運行被稱爲多態)。但是,如果我運行:
User.where(email: '[email protected]').user_notifications
,有人告訴我:
undefined method `user_notifications'
這應該給我相同的用戶正如我上面使用「查找」方法。在我的應用程序中,我在使用current_user時遇到了與user_notification相同的問題。例如,我有:
@notifications = current_user.user_notifications.inspect
我做這個登錄時,因爲我是在控制檯的工作相同的用戶,用戶31.然而,user_notifications顯示爲無。
如何通過current_user訪問user_notification?
謝謝,這對控制檯問題的工作。這是爲什麼?我絕對只有一個用戶使用該電子郵件地址? – Philip7899