Hi, I am trying to use the new rails 3 validations and running into some issues. for my password I have, validates :password, :presence => {:on => :create}, :length => { :minimum => 5, :maximum => 16 }, :confirmation => true the presence and length are creating problem. I only want to be able to check for the password at create time to confirm if it is present. at update time if someone enters the password it should still match the size limit but it they do not enter the password then it should not be looked at. in my controller i have already added: params[:user].delete(:password) if params[:user][:password].blank? params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? to take care of any issue coming from that side. any help or suggestion will be greatly appriciated. -- 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 Wed, May 11, 2011 at 2:36 AM, Quee WM <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I am trying to use the new rails 3 validations and running into some > issues. > > for my password I have, > > validates :password, :presence => {:on => :create}, :length => { > :minimum => 5, :maximum => 16 }, :confirmation => true > > the presence and length are creating problem. > > I only want to be able to check for the password at create time to > confirm if it is present. > > at update time if someone enters the password it should still match the > size limit but it they do not enter the password then it should not be > looked at. >My sense is that what is tripping things up is that on update and nil password, it is not checking precence but is still checking length and confirmation. It may not be the best way but I tend to use an :if => :method_name, and then in that method check for new_record, etc.> > in my controller i have already added: > > params[:user].delete(:password) if params[:user][:password].blank? > params[:user].delete(:password_confirmation) if > params[:user][:password].blank? and > params[:user][:password_confirmation].blank? > > to take care of any issue coming from that side. > > any help or suggestion will be greatly appriciated. > > -- > 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. > >-- 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.
Thanks for the reply David. I am not that good is rails so will need a bit more help. Is it possible for you to provide me with an example on how to use this if condition. I searched on the net and it did not become as clear to me. Regards, Q -- 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.
You may try this: validates :password, :if => Model.create{:presence => true}, :length => { :minimum => 5, :maximum => 16 }, :confirmation => true On Wed, May 11, 2011 at 1:06 PM, Quee WM <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I am trying to use the new rails 3 validations and running into some > issues. > > for my password I have, > > validates :password, :presence => {:on => :create}, :length => { > :minimum => 5, :maximum => 16 }, :confirmation => true > > the presence and length are creating problem. > > I only want to be able to check for the password at create time to > confirm if it is present. > > at update time if someone enters the password it should still match the > size limit but it they do not enter the password then it should not be > looked at. > > in my controller i have already added: > > params[:user].delete(:password) if params[:user][:password].blank? > params[:user].delete(:password_confirmation) if > params[:user][:password].blank? and > params[:user][:password_confirmation].blank? > > to take care of any issue coming from that side. > > any help or suggestion will be greatly appriciated. > > -- > 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. > >-- Please consider the environment before printing this email. Regards, Surya -- 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.
Hey, it would help to include your full functions that you are talking about, as well as the error messages you are experiencing (if so). -- 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.