Dear All i follow the instruction of Ruby on rails 3 tutorial, now i want to update the email of the User, user =User.find(1) user.update_attributes(:email=>"test-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org") but the save failed, error message is "password can not be blank", so i try this one user.update_attributes(:email=>"test-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org", :password =>"12345678") then it success,but i dont want to update the password, i try a lots times that is i want to change the value of other attributes, i must update the password, if not ,the updating will fail. how can i update without updating the password ? -- 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 Tue, Jan 17, 2012 at 9:12 AM, Daisy Di <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dear All > i follow the instruction of Ruby on rails 3 tutorial, now i want to > update the email of the User, > user =User.find(1) > user.update_attributes(:email=>"test-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org") > > but the save failed, error message is "password can not be blank", > so i try this one > user.update_attributes(:email=>"test-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org", :password =>"12345678") > then it success,but i dont want to update the password, i try a lots > times that is i want to change the value of other attributes, i must > update the password, if not ,the updating will fail. > > how can i update without updating the password ? >Check the User model (../app/models/user.rb) and see if there is a validation on password, present, could be e.g. validates :password, :presence => true If you not requre a password to be present, you could deactive that line. Or, alternatively, you could make sure a password is filled in for the user. You can check these valdiation errors e.g. with this code user.valid? # false if some validation failed user.errors.messages # all the validations that failed 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.
Peter Vandenabeele wrote in post #1041264:> On Tue, Jan 17, 2012 at 9:12 AM, Daisy Di <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> times that is i want to change the value of other attributes, i must >> update the password, if not ,the updating will fail. >> >> how can i update without updating the password ? >> > > Check the User model > (../app/models/user.rb) > and see if there is a validation on password, present, could be e.g. > > validates :password, :presence => true > > If you not requre a password to be present, you could deactive that > line. > > Or, alternatively, you could make sure a password is filled in for the > user. > > You can check these valdiation errors e.g. with this code > > user.valid? # false if some validation failed > user.errors.messages # all the validations that failed > > HTH, > > PeterHI Peter, Thanks for your advise, i add attr_accessor :password_confirmation ro user.rb and then delete validates :password, :presence => true and then , the problem is resolved. -- 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.
change you password validation to add :on => :create to your password validation. It makes it so the validations are only called for the specified controller action. example: validates :password, :presence => true, :on => :create Check out the rails guide for more info http://guides.rubyonrails.org/active_record_validations_callbacks.html#on On Jan 17, 3:12 am, Daisy Di <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dear All > i follow the instruction of Ruby on rails 3 tutorial, now i want to > update the email of the User, > user =User.find(1) > user.update_attributes(:email=>"t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org") > > but the save failed, error message is "password can not be blank", > so i try this one > user.update_attributes(:email=>"t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org", :password =>"12345678") > then it success,but i dont want to update the password, i try a lots > times that is i want to change the value of other attributes, i must > update the password, if not ,the updating will fail. > > how can i update without updating the password ? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.