이 레일 프로젝트는 시작한 지 오래되었으며 매우 이상한 허점이나 패치를하지 않았습니다.Rails : ActiveRecord :: Associations :: BelongsToAssociation을 String으로 변환 할 수 없습니다.
class Department < ActiveRecord::Base
belongs_to :school
def to_s
"foo" + (school || "bar")
end
end
보기 말한다 : 다음 그리고 to_s 문
하지만, 스크립트/콘솔에 대한
can't convert ActiveRecord::Associations::BelongsToAssociation into String
이 전무는 경우
모델, 그리고 to_s 바 학교를 대체 나는 학교 == nil이고 말하기학과 d를 가져갈 수 있습니다
학교가 전무없는 경우"foo" + (d.school || "bar")
및 "는 foobar"
동일한 오류가 나타납니다. – themirror