I''m trying to specify specific instances when
''validates_presence_of''
should be used in a particular model. I looked in the docs and found
that you can set :on to specify when the particular validation should
occur. However, I''m not sure how that should be formatted.
What I ultimately want to do is use the validation when I am creating a
record, but not when I am updating it.
Could someone help me out with the format here. My attempt (shown
below) doesn''t work.
validates_presence_of :email, :password, { :on => :save, :new }
Thanks!
Sarah
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Figured I''d follow this up myself since I found the answer myself. The correct format should have been: validates_presence_of :vf_email, :password, :on => :create Cheers, Sarah --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Per documentation (api.rubyonrails.org)...
on - Specifies when this validation is active (default is :save,
other
options :create, :update)
So change :new to :create and see what happens. If you still have
problems, then try making it two separate statements, as in...
validates_presence_of :email, :on => :save, :create
validates_presence_of :password, :on => :save, :create
c.
sarah_hutchinson wrote:> I''m trying to specify specific instances when
''validates_presence_of''
> should be used in a particular model. I looked in the docs and found
> that you can set :on to specify when the particular validation should
> occur. However, I''m not sure how that should be formatted.
>
> What I ultimately want to do is use the validation when I am creating a
> record, but not when I am updating it.
>
> Could someone help me out with the format here. My attempt (shown
> below) doesn''t work.
>
> validates_presence_of :email, :password, { :on => :save, :new }
>
> Thanks!
> Sarah
--
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
-~----------~----~----~----~------~----~------~--~---
Sorry - clicked submit too quickly... you don''t want the :save in there... validates_presence_of :email, :password, :on => :create or validates_presence_of :email, :on => :create validates_presence_of :password, :on => :create should work. c. Cayce Balara wrote:> Per documentation (api.rubyonrails.org)... > > on - Specifies when this validation is active (default is :save, > other > options :create, :update) > > So change :new to :create and see what happens. If you still have > problems, then try making it two separate statements, as in... > > validates_presence_of :email, :on => :save, :create > validates_presence_of :password, :on => :save, :create > > c. > > > > sarah_hutchinson wrote: >> I''m trying to specify specific instances when ''validates_presence_of'' >> should be used in a particular model. I looked in the docs and found >> that you can set :on to specify when the particular validation should >> occur. However, I''m not sure how that should be formatted. >> >> What I ultimately want to do is use the validation when I am creating a >> record, but not when I am updating it. >> >> Could someone help me out with the format here. My attempt (shown >> below) doesn''t work. >> >> validates_presence_of :email, :password, { :on => :save, :new } >> >> Thanks! >> Sarah-- 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 -~----------~----~----~----~------~----~------~--~---