當我執行命令有很多評論此錯誤時顯示的用戶列:獲取的has_many的在軌誤差(無法誤差)值
<% post.comments.each do |comment| %>
<div id="comments" >
<%= comment.user.email if comment.user.email != nil %>
<%= comment.comment %>
</div>
NoMethodError in Posts#index
Showing /Users/overallduka/Blog1/app/views/posts/index.html.erb where line #50 raised:
undefined method `email' for nil:NilClass
Extracted source (around line #50):
的意見模型有belongs_to的用戶和用戶模型has_many評論,因爲這個,但我沒有找到問題,我檢查和所有我的意見有user_id,請一些解決方案,請。
你提到您的所有意見都自己USER_ID定義的,但你確定它們都是有效的用戶ID?即可能評論具有不再存在的用戶的user_id。只有一種可能性。 –