On Sat, Oct 15, 2011 at 9:56 AM, Colin Law <[email protected]> wrote:
> On 15 October 2011 07:45, Misha Ognev <[email protected]> wrote: > > Tim, I know that somethn going wrong. But don't know, what. > > I think you need to explain your problem more carefully. I do not > think anyone knows exactly what you are asking. > I think the OP is trying to save to the database without validaton and is confusing * update_attributes (which does perform the validations) * update_attribute (which can update an attribute in the db without validations) This example might help: <code> class Referral < ActiveRecord::Base belongs_to :user validates :comment, :presence => true end $ rails c Loading development environment (Rails 3.1.1.rc1) 001:0> r = Referral.first Referral Load (0.6ms) SELECT "referrals".* FROM "referrals" LIMIT 1 => #<Referral id: 3, user_id: 2, comment: "developer", created_at: "2011-10-11 10:56:14", updated_at: "2011-10-11 10:56:14"> 002:0> r.update_attributes(:comment => nil) (0.4ms) BEGIN (0.3ms) ROLLBACK => false # FAILED (because of validation) 003:0> r.errors.messages => {:comment=>["can't be blank"]} # this is the validation that fails 004:0> r.update_attribute(:comment, nil) (0.4ms) BEGIN (1.0ms) UPDATE "referrals" SET "comment" = NULL, "updated_at" = '2011-10-16 15:43:22.544048' WHERE "referrals"."id" = 3 (1.3ms) COMMIT => true # the save succeeded, without checking the validation 005:0> r => #<Referral id: 3, user_id: 2, comment: nil, created_at: "2011-10-11 10:56:14", updated_at: "2011-10-16 15:43:22"> HTH, Peter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

