I have a model named as user, this model have check of password between length 6 to 16. But there are some scenarios where i cannot provide password while creating instance of user model. Here i am unable to save partial entries in database because validation forbids me. I want to know is there any to bypass validation checks in models --~--~---------~--~----~------------~-------~--~----~ 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 Aug 21, 7:39 pm, "Arslan Ali" <arslan....-2PoVgp36F/1eoWH0uzbU5w@public.gmane.org> wrote:> I have a model named as user, this model have check of password between > length 6 to 16. But there are some scenarios where i cannot provide password > while creating instance of user model. Here i am unable to save partial > entries in database because validation forbids me. >> I want to know is there any to bypass validation checks in modelswell if you pass false to save it won''t validate, or you can use the :if/:unless options on the validations to control when they run. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here''s how I''ve done it.
attr_accessor :step # to hold the step in the process
with_options :if => Proc.new{|record| record.step => 2} do |r|
r.validates_presence_of :credit_card, :ccv_code, :expiration_date
r.validates_numericality_of :credit_card
### other validations
end
On Thu, Aug 21, 2008 at 1:40 PM, Frederick Cheung <
frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> On Aug 21, 7:39 pm, "Arslan Ali"
<arslan....-2PoVgp36F/1eoWH0uzbU5w@public.gmane.org> wrote:
> > I have a model named as user, this model have check of password
between
> > length 6 to 16. But there are some scenarios where i cannot provide
> password
> > while creating instance of user model. Here i am unable to save
partial
> > entries in database because validation forbids me.
> >
>
> > I want to know is there any to bypass validation checks in models
> well if you pass false to save it won''t validate, or you can use
> the :if/:unless options on the validations to control when they run.
>
> Fred
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
and of course there''s a typo.
with_options :if => Proc.new{|record| record.step => 2} do |r|
should be
with_options :if => Proc.new{|record| record.step == 2} do |r|
:(
On Thu, Aug 21, 2008 at 1:46 PM, Brian Hogan
<bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Here''s how I''ve done it.
>
>
> attr_accessor :step # to hold the step in the process
>
> with_options :if => Proc.new{|record| record.step => 2} do |r|
> r.validates_presence_of :credit_card, :ccv_code, :expiration_date
> r.validates_numericality_of :credit_card
> ### other validations
>
> end
>
>
> On Thu, Aug 21, 2008 at 1:40 PM, Frederick Cheung <
> frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>>
>>
>>
>> On Aug 21, 7:39 pm, "Arslan Ali"
<arslan....-2PoVgp36F/1eoWH0uzbU5w@public.gmane.org> wrote:
>> > I have a model named as user, this model have check of password
between
>> > length 6 to 16. But there are some scenarios where i cannot
provide
>> password
>> > while creating instance of user model. Here i am unable to save
partial
>> > entries in database because validation forbids me.
>> >
>>
>> > I want to know is there any to bypass validation checks in models
>> well if you pass false to save it won''t validate, or you can
use
>> the :if/:unless options on the validations to control when they run.
>>
>> Fred
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Arslan Ali wrote:> I have a model named as user, this model have check of password between > length 6 to 16. But there are some scenarios where i cannot provide > password > while creating instance of user model. Here i am unable to save partial > entries in database because validation forbids me. > > I want to know is there any to bypass validation checks in modelsI don''t know if you are using validates_format_of like I am but here is an example of what I did: validates_format_of :password, :with => /^\w+$/, :message => ''<b style = "color:red">Password must be alphanumeric</b>'', :on => :create -S -- 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 -~----------~----~----~----~------~----~------~--~---