我在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
由于
答案 0 :(得分:0)
您可以使用Active Model Dirty模块,请参阅此处http://api.rubyonrails.org/classes/ActiveModel/Dirty.html