많은 과목 (별도 모델)이있는 교사 프로파일 모델이 있습니다. 프로파일을 생성/편집하기 위해 동일한 양식의 주제에 주제를 추가하고 싶습니다. accepts_nested_attributes를 사용하고 있습니다.이 작업은 생성시 잘 작동합니다. 그러나 편집 페이지에서 매우 이상한 오류가 발생합니다. 3 개의 피사체를 보지 않고 (작성시 3 개를 추가하고 콘솔에있는 모습을 확인) 대신 12 개의 피사체 (!)가 표시됩니다. 경우에중첩 된 속성 허용 - 수정 양식에 잘못된 항목 수가 표시됨 (+! map : ActiveSupport :: OrderedHash {})
#Profile model
class Profile < ActiveRecord::Base
has_many :subjects
accepts_nested_attributes_for :subjects
end
#Subject Model
class Subject < ActiveRecord::Base
belongs_to :profile
end
#Profile Controller (only showing deviations from normal RESTFUL setup)
def new
@profile = Profile.new
3.times do
@profile.subjects.build
end
end
#Here's 1 of three parts of the subject output of = debug @profile
errors: !ruby/object:ActiveRecord::Errors
base: *id004
errors: !map:ActiveSupport::OrderedHash {}
subjects:
- &id001 !ruby/object:Subject
attributes:
exam: Either
name: "7"
created_at: 2010-04-15 10:38:13
updated_at: 2010-04-15 10:38:13
level: Either
id: "31"
profile_id: "3"
attributes_cache: {}
# Note that 3 of these attributes are displayed despite me seeing 12 subjects on screen
다른 정보는 관련입니다.
레일 : - 나는 이미 약 8 시간 잃었다 2.3.5, 루비 1.8.7 p149, HAML는 전에
내가 버그로 너무 많은 어려움을 가진 적이 없었습니다 inherited_resources. 어떤 도움을 정말 고맙겠 어! 어떤 용기 응시자
잭
당신이'edit'에 사용하고있는 코드를 게시하시기 바랍니다 수 있습니까? –
컨트롤러를 얇게 유지하기 위해 inherited_resources를 사용하여 표준 편집 만합니다. 이것이 문제를 일으키지 않았다는 것을 다시 한번 확인하기 위해서 나는 컨트롤러를 아무런 쓸데없는 표준 컨트롤러로 다시 썼다. –