# I have a somewhat basic question, I have my User Model with the
following attributes:
#
#
# User.email
# User.hashed_password
# User.salt
#
# Attr Accessors
#
# User.password_confirmation
# User.email_confirmation
#
class User < ActiveRecord::Base
validates_length_of :password, :within => 5..40
validates_uniqueness_of :email
validates_presence_of :email, :email_confirmation, :password,
:password_confirmation
validates_confirmation_of :password
validates_confirmation_of :email
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+
[a-z]{2,})$/i, :message => "email address didn''t validate,
example
john-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org"
attr_protected :id, :salt
attr_accessor :password, :password_confirmation, :email_confirmation
end
#
# In my users_controller, I have 2 action, change_email and
change_password.
#
# What is the best way to update for just a password change OR email
change (different actions). The reason
# I''m asking this is that whenever I try and save just password and
password_confirmation, rails returns
# errors for email not being present. (it''s not on the form in
change_password action)
#
# My problem seems to be this, all my users validators are firing even
though I''m only editting a select
# attributes from my model.
#
# What''s the best solution guys?
#
# Thanks,
# - Viral
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Here''s how it should look like:
class User < ActiveRecord::Base
validates_length_of :password, :within => 5..40
validates_uniqueness_of :email
validates_presence_of :email, :password
validates_confirmation_of :password, :if => :password_changed?
#require confirmation only if it has changed
validates_confirmation_of :email, :if => :email_changed?
validates_format_of :email, :with =>
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "email
address didn''t validate, example
john-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org"
attr_protected :id, :salt
attr_accessor :password, :password_confirmation, :email_confirmation
end
-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
On Tue, Feb 24, 2009 at 4:55 PM, Viral
<rob-j6S4/CP4hf9BDgjK7y7TUQ@public.gmane.org>
wrote:>
> # I have a somewhat basic question, I have my User Model with the
> following attributes:
> #
> #
> # User.email
> # User.hashed_password
> # User.salt
> #
> # Attr Accessors
> #
> # User.password_confirmation
> # User.email_confirmation
> #
>
> class User < ActiveRecord::Base
>
> validates_length_of :password, :within => 5..40
> validates_uniqueness_of :email
>
>
> validates_presence_of :email, :email_confirmation, :password,
:password_confirmation
>
> validates_confirmation_of :password
> validates_confirmation_of :email
>
> validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+
> [a-z]{2,})$/i, :message => "email address didn''t validate,
example
> john-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org"
>
> attr_protected :id, :salt
>
> attr_accessor :password, :password_confirmation, :email_confirmation
>
> end
>
> #
> # In my users_controller, I have 2 action, change_email and
> change_password.
> #
> # What is the best way to update for just a password change OR email
> change (different actions). The reason
> # I''m asking this is that whenever I try and save just password
and
> password_confirmation, rails returns
> # errors for email not being present. (it''s not on the form in
> change_password action)
> #
> # My problem seems to be this, all my users validators are firing even
> though I''m only editting a select
> # attributes from my model.
> #
> # What''s the best solution guys?
> #
> # Thanks,
> # - Viral
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Yup, that''s basically what I did when I gutted everything to use AuthenicatedSystem (acts_as_authenicated) Thanks ;D On Feb 25, 11:17 am, Maurício Linhares <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s how it should look like: > > class User < ActiveRecord::Base > > validates_length_of :password, :within => 5..40 > validates_uniqueness_of :email > > validates_presence_of :email, :password > > validates_confirmation_of :password, :if => :password_changed? > #require confirmation only if it has changed > validates_confirmation_of :email, :if => :email_changed? > > validates_format_of :email, :with => > /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "email > address didn''t validate, example j...-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" > > attr_protected :id, :salt > > attr_accessor :password, :password_confirmation, :email_confirmation > > end > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > > On Tue, Feb 24, 2009 at 4:55 PM, Viral <r...-j6S4/CP4hf9BDgjK7y7TUQ@public.gmane.org> wrote: > > > # I have a somewhat basic question, I have my User Model with the > > following attributes: > > # > > # > > # User.email > > # User.hashed_password > > # User.salt > > # > > # Attr Accessors > > # > > # User.password_confirmation > > # User.email_confirmation > > # > > > class User < ActiveRecord::Base > > > validates_length_of :password, :within => 5..40 > > validates_uniqueness_of :email > > > validates_presence_of :email, :email_confirmation, :password, :password_confirmation > > > validates_confirmation_of :password > > validates_confirmation_of :email > > > validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+ > > [a-z]{2,})$/i, :message => "email address didn''t validate, example > > j...-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" > > > attr_protected :id, :salt > > > attr_accessor :password, :password_confirmation, :email_confirmation > > > end > > > # > > # In my users_controller, I have 2 action, change_email and > > change_password. > > # > > # What is the best way to update for just a password change OR email > > change (different actions). The reason > > # I''m asking this is that whenever I try and save just password and > > password_confirmation, rails returns > > # errors for email not being present. (it''s not on the form in > > change_password action) > > # > > # My problem seems to be this, all my users validators are firing even > > though I''m only editting a select > > # attributes from my model. > > # > > # What''s the best solution guys? > > # > > # Thanks, > > # - Viral--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---