-1
revisor_id
모델을 Petition
모델로 업데이트하면 revisor_id
을 Post
모델에서 자동으로 업데이트하려고합니다.은 레일의 필드를 업데이트 할 수 없습니다.
그래서, 내 petitions_controller.rb
에서 나는 update
메서드 내에서이 줄을 추가 :
@petition.post.revisor_id = @petition.revisor_id
을 내가 줄이 실행 된 후, 모두가 올바르게 설정되어 있는지 볼 수있는 디버거. 하지만 revisor_id가 1로 설정된 모든 게시물을 표시하도록 요청하면 아무 것도 표시하지 않기 때문에 데이터베이스 나 다른 사람에게 저장되지 않은 것 같습니다.
필자는 레일 4로 변경 되었기 때문에 강력한 매개 변수와 관련이 있다고 생각하지만 확실하지는 않습니다.
아이디어가 있으십니까?
#petitions_controller.rb
...
def update
respond_to do |format|
if @petition.update(petition_params)
@petition.post.revisor_id = @petition.revisor_id
format.html { redirect_to @petition, notice: 'Petition was successfully updated.' }
format.json { render :show, status: :ok, location: @petition }
else
format.html { render :edit }
format.json { render json: @petition.errors, status: :unprocessable_entity }
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_petition
@petition = Petition.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def petition_params
params.require(:petition).permit(:user_id, :category_id, :revisor_id, :status, :post_id)
end
서버 로그를 게시 할 수 있습니까? – Pavan