# Ignoring Validations In An Admin Tool?

**URL:** <https://www.ruby-forum.com/t/ignoring-validations-in-an-admin-tool/56555>\
**Category:** Rails\
**Created:** [April 1, 2006, 2:25am UTC](https://www.ruby-forum.com/t/ignoring-validations-in-an-admin-tool/56555 "2006-04-01T02:25:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [April 1, 2006, 2:25am UTC](https://www.ruby-forum.com/t/ignoring-validations-in-an-admin-tool/56555/1 "2006-04-01T02:25:40Z")

</div>

I have the following validation on and ‘Order’ model:

validates\_presence\_of :order\_lines, :message =\> ‘missing one or more  
products.’, :on =\> :save

Ok, great. An order has to have products. Ok.

Problem is, there are some old orders that don’t have lines (don’t ask)  
and  
in the admin tool we need to be able to work on these orders.

Problem is that we can’t save them since they technically fail  
validation.  
In the admin tool I want to be able to get around this.

I’m using two methods to update order status, depending on if we’re  
doing  
lots of 'em at a time:

Order.update(params[:item].keys, params[:item].values)

Or just one:

```
@order = Order.find(params[:id])
@order.update_attributes(params[:order])

```

So, can anyone offer any advice in this scenario to bypass validations  
and  
update the objects/save them?

Thx,  
Hunter

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [April 1, 2006, 2:52am UTC](https://www.ruby-forum.com/t/ignoring-validations-in-an-admin-tool/56555/2 "2006-04-01T02:52:52Z")

</div>

On Fri, 2006-03-31 at 16:23 -0800, HH wrote:

> Problem is that we can’t save them since they technically fail validation.  
> @order.update\_attributes(params[:order])
> 
> So, can anyone offer any advice in this scenario to bypass validations and  
> update the objects/save them?

* * *

maybe I am dense but couldn’t you just use sql to add what you need - be  
they columns or rows ? …i.e. insert into … where …

Craig

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [April 1, 2006, 3:14am UTC](https://www.ruby-forum.com/t/ignoring-validations-in-an-admin-tool/56555/3 "2006-04-01T03:14:11Z")

</div>

On Saturday 01 Apr 2006 01:23, HH wrote:

> ```
> @order = Order.find(params[:id])
> @order.update_attributes(params[:order])
> 
> ```
> 
> So, can anyone offer any advice in this scenario to bypass validations and  
> update the objects/save them?

Kinda sounds to me like you want:  
update\_attribute\_with\_validation\_skipping

See:  
[http://api.rubyonrails.com/classes/ActiveRecord/Validations.html#M000796](http://api.rubyonrails.com/classes/ActiveRecord/Validations.html#M000796)

Though as far as I know, there’s no way of doing update\_attributes and  
bypassing all validations.

Another possibility for you would be to put validation conditions into  
your  
model using :if =\>

validates\_presence\_of :order\_lines, :message =\> ‘missing one or more  
products.’, :on =\> :save, :if =\> some\_condition

HOWEVER, as far as I know, the models aren’t supposed to be tightly  
linked to  
the controllers and have a good degree of enforced separation between  
them,  
so if you were going to check for the presence of a session variable (or  
something) in your model, I think you’ll be out of luck as that kind of  
stuff  
belongs in the controller.

There’s probably a way you could do it but I can’t think right now,  
sorry!

~Dave

–

Dave S.  
Rent-A-Monkey Website Development

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [April 1, 2006, 5:39am UTC](https://www.ruby-forum.com/t/ignoring-validations-in-an-admin-tool/56555/4 "2006-04-01T05:39:55Z")

</div>

Another choice is to create the base model without the validations and  
then inherit from it to add the validations. In the normal case use  
the properly validated model, but when necessary fall back to the base  
model.

pth
