I have one big problem: when I try record to db through update_attributes! (which must save when record invalid). All good, all validates :field, :presence => true et.c. field ignored, but validates_with no ignore! So, it raises an error:> Validation failed: Captcha wrong captcha inputCaptchaValidator works with many models, so I put it to captcha_validator.rb But I want to save with ignore this field. What I must do? -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Friday, October 14, 2011 2:53:20 AM UTC-4, Ruby-Forum.com User wrote:> > I have one big problem: when I try record to db through > update_attributes! (which must save when record invalid).I''m not so sure that''s entirely accurate. Check out the API for update_attributes! and save! methods: http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_attributes-21 http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save-21 Specifically: update_attributes! updates its receiver just like update_attributes but calls save! With save! validations always run. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ytBn6RxuB20J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim, I know that somethn going wrong. But don''t know, what. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 October 2011 07:45, Misha Ognev <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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. Colin -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, Oct 15, 2011 at 9:56 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 15 October 2011 07:45, Misha Ognev <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.