Rails 4 앱에서 다형성 연결을 설정하는 데 문제가 있음을 파악하고 있습니다.Rails 4 - 중첩 된 다형성 속성에 대한 업데이트 작업이있는 다형성 연관
프로젝트 모델과 주소 모델이 있습니다. 협회는 다음과 같습니다 나는 이전에 같은 문제에 질문을
belongs_to :addressable, :polymorphic => true
프로필
has_many :addresses, as: :addressable
accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true
주소. 해당 게시물의 답변을 이해할 수 없었습니다. (아직까지는 답변 할 수 없습니다) Rails 4 - Polymorphic associations
이번에는 - 주소를 삽입하여 프로필을 업데이트하려고 할 때 발생하는 문제가 있습니다. 오류 메시지는 프로파일 컨트롤러의 갱신 조치에서 오는 문제점을 식별합니다. 업데이트 작업이 있습니다
내 프로필 컨트롤러 업데이트 작업이 있습니다
def update
# successful = @profile.update(profile_params)
# Rails.logger.info "xxxxxxxxxxxxx"
# Rails.logger.info successful.inspect
# [email protected]
# user.update.avatar
# Rails.logger.info "prof xxxxxxxxxxxxx"
# Rails.logger.info @profile.update(profile_params)
respond_to do |format|
if @profile.update(profile_params)
format.html { redirect_to @profile }
format.json { render :show, status: :ok, location: @profile }
else
format.html { render :edit }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
오류 메시지가 말한다 :
ERROR: duplicate key value violates unique constraint "index_addresses_on_addressable_type_and_addressable_id"
DETAIL: Key (addressable_type, addressable_id)=(Profile, 1) already exists.
사람은이 메시지가 무엇을 의미하는지 알고 있나요, 어떻게 그것을 해결하기 위해?
이것은 PSQL 오류입니다의 종류를 제공 할 수 있습니다
희망은, 이미 "1"로 "프로파일"을 addressable_id로 addresable_type으로 데이터베이스에 항목이 있음을 의미한다. 즉, 업데이트 작업에서 새 주소 지정 가능을 만드는 중입니다. – nzajt
기존 레코드의 업데이트를 어떻게 알 수 있습니까? – Mel