2014-03-12 1 views
0

내 모델에서 :class_name => "user" 조항으로 인해 오류가 발생했습니다. 어떤 아이디어?레일스 모델의 열에 클래스 이름 할당

세부 내가 레일에서 매우 간단한 자체 참조 모델을 가지고있다. 그것은 2 명의 사용자 간의 우정입니다. 내보기에서

class Friendship < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :friend, :class_name => "user" 
end 

, 난 아래 <%= @friendship.friend.name %>를 추가 할 때 발생하는 오류 uninitialized constant RoomidexRelationship::user를 얻을.

<p> 
    <%= @friendship.user.name %> 
</p> 

<p> 
    <%= @friendship.friend.name %> 
</p> 

답변

1

클래스 이름은

class Friendship < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :friend, :class_name => "User" 
end 
CamelCase를

에 있어야합니다
관련 문제