Hi all, In user model i have 4 validations. In an update i need to skip 2 of those validations and other 2 need to fire. Please help how to do that. Thanks in advance -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote:> In user model i have 4 validations. In an update i need to skip 2 > of those validations and other 2 need to fire.:on => create -faisal --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Faisal N Jawdat wrote:> On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote: >> In user model i have 4 validations. In an update i need to skip 2 >> of those validations and other 2 need to fire. > > :on => create > > -faisalThanks for your response.... let me give detail information i have validations on email, password, password length etc... i have the following methods 1. signup 2. forgot password 3. change password In the above 3 scenarios i am using save and update methods here both validations should exist 4. Update user (no password field) In this scenario i need to skip the password validation for length plz help me -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This does not sound right to me. WHen you save a user object you should either have a password or not have one. If you allow the user to exist with no password then your validations should be done conditionally in your validate method. But, I would not allow a user to exist without a password, that is a bad security setup. Validations happen at the model level not the form level, so you are validating the entire user record not just the fields being changed by a form. If I misunderstood your situation pleas include more detail. Michael On May 25, 8:22 am, Pradeep Maddi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Faisal N Jawdat wrote: > > On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote: > >> In user model i have 4 validations. In an update i need to skip 2 > >> of those validations and other 2 need to fire. > > > :on => create > > > -faisal > > Thanks for your response.... > > let me give detail information > > i have validations on email, password, password length etc... > > i have the following methods > > 1. signup > 2. forgot password > 3. change password > > In the above 3 scenarios i am using save and update methods here both > validations should exist > > 4. Update user (no password field) > > In this scenario i need to skip the password validation for length > > plz help me > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
First a more direct answer to your question:
ActiveRecord supplies validate_on_create and validate_on_update as
separate methods from validate.  If you really wanted validation of
creation of objects, but not on update you could put your validation
in validate_on_create.
However, it sounds like you have a fundamental misunderstanding of
validation (as eluded to in a previous reply).  If you are validating
a user''s password for presence and length then you should always
perform that check.
class User < ActiveRecord::Base
  validates_presence_of :username, :password
  validates_length_of :password, :minimum => 6
  validate_on_create
    #put your create validations here
  end
  validate_on_update
    #put your update validations here
  end
end
It almost sounds like you are validating somewhere else besides the
model.  If you are doing that then....well don''t.  What happens if
records are inserted or updated without going through your view or
controller.
On May 25, 1:40 pm, MichaelLatta <lat...-ee4meeAH724@public.gmane.org>
wrote:> This does not sound right to me.
>
> WHen you save a user object you should either have a password or not
> have one.  If you allow the user to exist with no password then your
> validations should be done conditionally in your validate method.
> But, I would not allow a user to exist without a password, that is a
> bad security setup.  Validations happen at the model level not the
> form level, so you are validating the entire user record not just the
> fields being changed by a form.
>
> If I misunderstood your situation pleas include more detail.
>
> Michael
>
> On May 25, 8:22 am, Pradeep Maddi
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
> wrote:
>
> > Faisal N Jawdat wrote:
> > > On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote:
> > >> In user model i have 4 validations. In an update i need to
skip 2
> > >> of those validations and other 2 need to fire.
>
> > > :on => create
>
> > > -faisal
>
> > Thanks for your response....
>
> > let me give detail information
>
> > i have validations on email, password, password length etc...
>
> > i have the following methods
>
> > 1. signup
> > 2. forgot password
> > 3. change password
>
> > In the above 3 scenarios i am using save and update methods here both
> > validations should exist
>
> > 4. Update user (no password field)
>
> > In this scenario i need to skip the password validation for length
>
> > plz help me
>
> > --
> > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi
from what i have understood:
firstly u need to get a instance of the user you want to update
@user = users.find( :first, :conditions => { :id => your id} )
 now update the instance and call update on this instance
the validations are already in the right place so no need to change
them
cheers...
On May 25, 8:22 am, Pradeep Maddi
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Faisal N Jawdat wrote:
> > On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote:
> >> In user model i have 4 validations. In an update i need to skip 2
> >> of those validations and other 2 need to fire.
>
> > :on => create
>
> > -faisal
>
> Thanks for your response....
>
> let me give detail information
>
> i have validations on email, password, password length etc...
>
> i have the following methods
>
> 1. signup
> 2. forgot password
> 3. change password
>
> In the above 3 scenarios i am using save and update methods here both
> validations should exist
>
> 4. Update user (no password field)
>
> In this scenario i need to skip the password validation for length
>
> plz help me
>
> --
> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---