It looks like you''re confusing Model.update with
@model.update_attributes. Model.update(id, attributes) should be
called on the class, not an instance.
Person.update(1, { :name => ''Jonathan'' })
Is equivalent to:
p = Person.find(1)
p.update_attributes({:name => ''Jonathan''})
Surprisingly, p.update actually saves the record without looking at
the validation... that could be classed as misleading at best. You
should use update_attributes, not update.
ActiveRecord::Base#update is private in base.rb, but locking.rb does
not preserve its private status. Looks like a small bug, I''ll file it
tomorrow.
-Jonathan.
On 6/21/06, Gerald Schenke <realazrael@gmx.de>
wrote:> Searched for it, but found nothing, so i open a new topic :/
> I think it is very basic stuff...
>
> My model has a validation rule like this:
> validates_presence_of :title
>
> If i try to save the model (@mymodel.save) with an empty title-formfield
> i get an error. hooray! that''s what i want!
> okay i insert a valid title and everything is fine.
>
> now i want to update the model (@mymodel.update) and - SURPRISE! - now
> i can update title to an empty string ""! Why?
>
> Even if i have this in my rule
> validates_presence_of :title, :on => :update
> i can update my model without an error and have an empty string for the
> title in my database.
>
> i dont get it. the API says:
> update(id, attributes)
> Finds the record from the passed id, instantly saves it with the passed
> attributes (if the validation permits it), and returns it.
>
> but it does not validate!!
> i''m using rails 1.1.2
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>