我在 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
谢谢