belongs_to
관계에서 연결 확장을 수행 할 수 있습니까?belongs_to의 Activerecord 연결 확장
내가 전화 했어 방법은 개인이라고 말했다되는 :
module TestExtension
def test
puts 'test successful'
end
end
class Question < ActiveRecord::Base
belongs_to :user, extend: TestExtension
end
는 방법은 개인 것을 불평하지만 내가 그것을 실행할 때마다
q = Question.first
q.test
# => NoMethodError: Attempt to call private method `test'
belongs_to에서 AR 확장을 수행 할 수 있는지 여부가 100 % 명확하지 않습니다. Rails 3.0.7에서는 정상적으로 작동했지만 현재는 3.1.0에서 실패했습니다.
어디서 TestExtension 모듈을 넣으시겠습니까? lib 디렉토리의 새 파일에? – Coderama