좋습니다.이 파일은 정상입니다. 나는 다음과 같은 다른 것들 중에서, 관계를 포함, 액티브 오브젝트 있습니다Rails 자체 참조 HABTM 활성 레코드 객체에 대한 중첩 된 편집 양식
class Sample < ActiveRecord::Base
has_and_belongs_to_many :related_samples,
:class_name => "Sample",
:join_table => "related_samples",
:foreign_key => "sample_id"
:associated_foreign_key => "related_id"
end
을 그리고 여기에 대한 계획입니다 :
def self.up
create_table :samples do |t|
t.string :related_info
t.string :name
#There's other info, but it is not related to this problem
end
create_table :related_samples, :id => false do |t|
t.references :sample
t.references :related
t.timestamps
end
end
이 완벽하게 작동합니다. sample_object.related_samples를 요청하면, 내가 할당 한 다른 Sample 객체가 무엇이든 제공합니다.
문제는 내보기에 대한 편집 작업과 함께 제공됩니다. 내 목표는 사용자가 사용 가능한 모든 샘플 목록에서 샘플 객체를 선택하여 기존의 관련 Sample 객체를 다른 샘플 객체로 대체 할 수있게하는 것입니다. 그리고 나는 이것을 (가능하다면) fields_for 헬퍼 메소드 내부에 구현하고 싶다. 그래서 업데이트를하는 것이 정말 간단하다. 이 방법을 구현하는 방법을 모르거나 심지어 할 수 있습니다. 가능한가? 그렇다면 어떻게?
이 문제를 해결 했습니까? – CharlieMezak