[Rails] Ignoring Validations In An Admin Tool?
Dave Silvester
dave at rentamonkey.com
Sat Apr 1 01:11:03 GMT 2006
On Saturday 01 Apr 2006 01:23, HH wrote:
> 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?
Kinda sounds to me like you want: update_attribute_with_validation_skipping
See: 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 Silvester
Rent-A-Monkey Website Development
http://www.rentamonkey.com/
PGP Key: http://www.rentamonkey.com/pgpkey.asc
More information about the Rails
mailing list