2012-10-22 187 views
2

我在mongoid中有一個驗證,如果它在保存錯誤信息時失敗了,我想恢復它。Mongoid恢復失敗

if @thing.update_attributes(params[:thing]) 
    format.html { redirect_to @thing, notice: 'Thing was successfully updated.' } 
    format.json { head :no_content } 
else 
    #revert the fields that have changed and keep @thing.errors 
    format.html { render action: "edit" } 
    format.json { render json: @thing.errors, status: :unprocessable_entity } 
end 

當我保存關閉文檔,然後重新插入,它似乎不想分配@thing.errors = errors

感謝

回答