出错信息如下 undefined method `name' for nil:NilClass
Extracted source (around line #26):
<% if [email protected]? %> <% @article.comments.each do |comment| %>
<%= link_to comment.author.name, user_path(comment.author) %>:<%= comment.content %>
<% end %> <% end %>
但是我在 model 中有写
class Comment < ActiveRecord::Base
belongs_to :article
belongs_to :author, class_name: "User", foreign_key: "user_id"
end
`class Article < ActiveRecord::Base belongs_to :owner, class_name: "User", foreign_key: "user_id" belongs_to :sub_category has_many :comments
attr_accessor :document end`
`class User < ActiveRecord::Base has_many :articles has_many :comments
has_secure_password end` 能指点下可能出错的原因吗