저는 Recover라는 모델로 작업하고 있습니다. 모델을 만들기 전에 Recover.combo_id 특성을 참조로 사용하여 부울 속성 인 Combo.occupied = true를 저장하고 싶습니다.콜백을 사용하여 다른 모델을 업데이트하려면 어떻게해야합니까?
내 SQL이 쿼리를 제대로 실행하고 있지만이 특성을 저장하지 않는 것으로 보입니다. Combo.occupied = true를 어떻게 저장할 수 있습니까?
recover.rb :
before_create :
가
DEF X = Combo.find_by_id (combo_id) .occupied = 진정한
단부 체크인 보호 체크인
레일 콘솔 :
는 HTML
매개 변수로 만들 17시 7분 24초 -0800
처리 RecoversController 번호로 2011-01-06에서 127.0.0.1 에 대한 POST "/ 회복"을 시작 : { "UTF8을"=> "✓", "authenticity_token"=> "o1Iu3Y9/rVBOZPoDUgVP/tRfQ8GxbdWC40DbPq9YxUE =", "복구"=> { "combo_id"= "4", "이메일"=> "[email protected]"}, 복구 "불러 오기 (0.2ms)"복구 ","ID " FROM"복구 "WHERE ("복구 ","이메일 "= '[email protected] arin.edu ') LIMIT 1
로드 (는 0.1ms 복구) 발 "회복". "ID"를 선택 WHERE ("회복". "combo_id"= 4) LIMIT 1
콤보로드 (를 0.5ms "회복") "combos". * WHOM "combos". "id"= 4) LIMIT 1 AREL (0.5ms) INSERT INTO "복구"("locker_number", "email", "요청 (NULL, '[email protected]', NULL, '2011-01-07 01 : 07 : 24.287072', ', "created_at", "updated_at", "combo_id" 01-07 01 : 07 : 24.287072 ', 4) http://localhost:3000/recovers/14로 리디렉션 됨가 119ms
RecoversController # 302 실측치 완료 됨이
데프 @recover = Recover.new 만들면된다 (PARAMS를 [: 복구])
'만들어 졌는지 복구. ')} 형식입니다.XML 렌더링 {: XML => @recover : 상태 => 생성respond_to do |format| if @recover.save format.html { redirect_to(@recover, :notice =>
: 위치 => @recover}
else format.html { render :action => "new" } format.xml { render :xml => @recover.errors, :status =>
: unprocessable_entity} 단부
end
단부
RecoversController # create에 개체가 만들어지지 않은 것 같습니다. 이 방법의 내용을 게시 할 수 있습니까? – apneadiving
그래. 그 완료 –