저는 Rails의 초보자입니다. 3 개의 컨트롤러/모델 (의사, 환자 및 보고서)으로 앱을 개발하고 있습니다. 닥터에는 많은 환자가 있고, 환자는 닥터에 속하며, 환자에게는 많은 보고서와 보고서가 환자에게 속해 있습니다. 컨트롤러가 테이블 레일에 액세스 할 수 없습니다.
이 API를 통해 외부에서 환자를 만들려면 내가 컨트롤러이 있습니다def create
if doc=params[:patient]
doctor_id=doc[:doctor]
else
puts 'NO PARAMS' =># this is just to monitor the status in the server
end
doctor=Doctor.find(doctor_id)
@patient=doctor.patients.new(
name: doc[:name],
email: doc[:email],
sex: doc[:sex],
password: doc[:password],
password_confirmation: doc[:password_confirmation])
if @patient.save
render json: { success: true, data: @patient.remember_token, status: :created }
else
render json: { success: false, data: @patient.errors, status: :unprocessable_entity }
end
end
이 예상대로 작동 : 나는 doctor_id를 검색하고 그와 관련된 새로운 환자를 만들 수 PARAMS에서.
하지만 정확히 똑같은 보고서를 작성하면 이상한 일이 발생했습니다.
def create
par=params[:report]
token=par[:patient_token]
pat=Patient.find_by_remember_token(token)
puts pat =>#this is to monitor the server
last_report=pat.reports.last
puts last_report =>#this is to monitor the server
if ((Time.now-last_report.created_at)/86400).round>0
report=create_report(par[:patient_token])
report.attributes=par
if report.save
render json: { success: true, data: report, status: :created }
else
render json: { success: false, data: report.errors, status: :unprocessable_entity }
end
else
last_report.attributes=par
if last_report.save
render json: { success: true, data: last_report, status: :created }
else
render json: { success: false, data: last_report.errors, status: :unprocessable_entity }
end
end
end
그리고이 시간 서버 충돌을하고 환자를 검색하지 않습니다 내 컨트롤러에서 나는 있습니다. pat = nil이므로 pat = Patient.find_by_remember_token (토큰)이 작동하지 않습니다.
왜 이런 일이 발생하는지 파악할 수 있습니까?
미리 감사드립니다.
해결책 : 모든 단서에 대한 모든 감사의
첫째는 솔루션에 저를 안내합니다. 디버거 보석 덕분에 "정말로"Patient.find_by_remember_token (토큰)에 전송 된 토큰이 잘못된 것으로 나타났습니다. 내말은. 내가
을 통해 서버의 토큰을 잡기되었다 토큰 => 어떤 반환 "X6MlhaRLFMoZRkYaGiojfA"(올바른 토큰)
하지만 디버거를 통해 I를 보낸 실제 토큰이
것을 실현 "\"두고 확실히 잘못이다 X6MlhaRLFMoZRkYaGiojfA \ "는"그래서 나는 다음의 방법으로 내 컬 쿼리 수정 :
ORIGINAL CURL: curl -X POST -d 'report[patient_token]="X6MlhaRLFMoZRkYaGiojfA"&repo
MODIFIED ONE: curl -X POST -d 'report[patient_token]=X6MlhaRLFMoZRkYaGiojfA&repo
을 그리고 그것은 빌어 먹을 ... 지연 5 시간을 사용할 수 있습니다.
감사합니다!
[: patient_token]은 (는) 존재합니까?, 그 값은 무엇입니까? –
예, 값 : "X6MlhaRLFMoZRkYaGiojfA" –
이므로이 remember_token을 가진 환자가 데이터베이스에 없습니다. –