2012-03-08 5 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のnilはありますか?そうであればエラーは有効です –

答えて

0

スキーマに「user」ではなく「commenter」が表示されているようです。

たぶん、あなたはあなたのcomment.rbで

belongs_to :commenter, :class_name => 'User', :foreign_key => 'user_id' 

を持っている必要があり

関連する問題