2012-03-08 39 views
0

这就是我所拥有的。代表设计用户不工作

item.rb的:

has_many :comments 
belongs_to :user 

user.rb:

devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

# Setup accessible (or protected) attributes for your model 

attr_accessible :email, :password, :password_confirmation, :remember_me, :display_name 
has_many :items 
has_many :comments, :through => :items 

comment.rb:

belongs_to :item 
belongs_to :user 
delegate :display_name, :to => :user, :prefix => true 

<%= comment.user_display_name%>正在恢复

Comment#user_display_name delegated to user.display_name, but user is nil: 
#<Comment id: 16, body: "fdsfsd", commenter_id: 1, item_id: 2, created_at: 
"2012-03-07 23:41:10", updated_at: "2012-03-07 23:41:10"> 
+0

是comment.user零?如果是的话那么错误是有效的 – 2012-03-08 03:13:40

回答

0

您似乎在模式中有'评论者'而不是'用户'。

也许你应该有

belongs_to :commenter, :class_name => 'User', :foreign_key => 'user_id' 
在comment.rb