Rails update attributes not validating

It does not instantiate the involved models and it does not trigger Active Record callbacks or validations.

if @user.update_attributes(params[:user]) flash[:success] = "Edit Successful." redirect_to @user else @title = "Edit user" render 'edit' end end Ah I feel bad now.

When the database catches such a duplicate insertion, Active Record:: Base#save will raise an Active Record:: Statement Invalid exception.

You can either choose to let this error propagate (which will result in the default Rails exception page being shown), or you can catch it and restart the transaction (e.g.

Validations are used to ensure that only valid data is saved into your database.

For example, it may be important to your application to ensure that every user provides a valid email address and mailing address.


Leave a Reply