나는 플러그인 내에서 새로운 관계를 동적으로 정의하는 플러그인을 작성 중이다. 샘플 코드는 모든 모델에서 지금인스턴스 변수에 저장된 모델의 속성을 얻는 방법
module AttachDocumentsAs
@as = nil
def attach_documents_as(*attachment_as)
attachment_as = attachment_as.to_a.flatten.compact.map(&:to_sym)
@as = attachment_as.first
class_inheritable_reader(@as)
class_eval do
has_many @as, :as => :attachable, :class_name=>"AttachDocuments::Models::AttachedDocument"
accepts_nested_attributes_for @as
end
end
end
아래에 주어진 내가
class Person < AtiveRecord::Base
attach_documents_as :financial_documents
end
지금이
def initialize(*args)
super(*args)
"#{@as}".build
end
같은 과부하 초기화 방법에 클래스의 속성에 액세스하려면 액세스 할
로 사용
하지만 필수 속성을 얻지 못하고 있습니다. 아무도 나를 도와 줄 수 없습니다. 이 관계를 만들고 초기 값을 설정하고 싶습니다.
여러분 모두의 지침을 기다리고 있습니다.
내가 class_inheritable_reader (@as) class_inheritable_reader 사용 지금 내 전 ( self.send로 self.send 그것을 얻을 수 초기화를 (: atd_as)) 하지만 이제 문제는 빌드를 호출하는 것입니다. self.send (self.send (: atd_as)) 빌드 이 작동하지 않습니다. –