2

I have a validations in mongoid that I want to revert if it fails while saving the error message.

Example

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

when I save off the document and reinsert it, it seems to not want to assign @thing.errors = errors

Thanks

GTDev
  • 5,488
  • 9
  • 49
  • 84

1 Answers1

0

You can use Active Model Dirty module, see here http://api.rubyonrails.org/classes/ActiveModel/Dirty.html

ryudice
  • 36,476
  • 32
  • 115
  • 163