0
我遇到問題更新記錄,使用保存。這是我的代碼到目前爲止爲什麼我的記錄沒有更新?
def update
if current_user.customer?
question = JobQuestion.find(job_question_params[:job_id])
question.answer = job_question_params[:answer]
# Only save, if the current user is the owner of the job.
if current_user.id == Job.find(job_question_params['job_id']).customer.id && question.save
raise JobQuestion.last.inspect
render json: { status: 201 }
end
end
end
但由於某種原因它不會更新,這是我的日誌輸出。
SQL (85.6ms) UPDATE "job_questions" SET "answer" = $1, "job_id" = $2, "question" = $3, "updated_at" = $4 WHERE "job_questions"."id" = 2 [["answer", "safsf"], ["job_id", 2], ["question", "test test test"], ["updated_at", Wed, 08 Jan 2014 15:04:16 UTC +00:00]]
(11.5ms) COMMIT
JobQuestion Load (0.9ms) SELECT "job_questions".* FROM "job_questions" ORDER BY "job_questions"."id" DESC LIMIT 1
Completed 500 in 218ms
RuntimeError - #<JobQuestion id: 3, job_id: 2, company_id: 2, question: "test test test", answer: nil, created_at: "2014-01-08 11:47:34", updated_at: "2014-01-08 14:17:00">:
app/controllers/api/job_questions_controller.rb:27:in `update'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
正如你所看到的那樣,加註是提取工作問題,但答案是零,甚至認爲它是插入的東西。
我在做什麼錯了?
Aww應該注意到了,謝謝 – MartinElvar