Hi For my users model, the password field cannot be the same as the username, which is checked by the validate method in the model: class User < ActiveRecord::Base ... def validate if password == username errors.add(:password, "Cannot be the username") end end end This works fine when creating a new user. However it fails when a user wants to change their password. The reason it fails is that the update/edit form view does *not* let the user change their username (usernames are static). So when the validate method (above) is ran it does not know what the username is. What is the rails-way for tackling this? thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well, I''ve partly fixed it by including a username hidden field. That way the username pararmeter will always be passed Not sure if thats the rails-way or not? :) On 09/10/2006, at 3:33 PM, Jason Bowerman wrote:> Hi > > For my users model, the password field cannot be the same as the > username, which is checked by the validate method in the model: > > > class User < ActiveRecord::Base > ... > def validate > if password == username > errors.add(:password, "Cannot be the username") > end > end > end > > > This works fine when creating a new user. However it fails when a > user wants to change their password. > > The reason it fails is that the update/edit form view does *not* let > the user change their username (usernames are static). So when the > validate method (above) is ran it does not know what the username is. > > What is the rails-way for tackling this? > > thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/9/06, Jason B <jasjbow-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Well, I''ve partly fixed it by including a username hidden field. > > That way the username pararmeter will always be passed > > Not sure if thats the rails-way or not? :) > > > On 09/10/2006, at 3:33 PM, Jason Bowerman wrote: > > > Hi > > > > For my users model, the password field cannot be the same as the > > username, which is checked by the validate method in the model: > > > > > > class User < ActiveRecord::Base > > ... > > def validate > > if password == username > > errors.add(:password, "Cannot be the username") > > end > > end > > end > > > > > > This works fine when creating a new user. However it fails when a > > user wants to change their password. > > > > The reason it fails is that the update/edit form view does *not* let > > the user change their username (usernames are static). So when the > > validate method (above) is ran it does not know what the username is. > > > > What is the rails-way for tackling this? > > > > thanks!I would think that if your table has a username field (called username) in it then this would not be a problem. Can you post some more information on your model? Relationships / validtaions. Not sure if it will help but some more information would be good. Cheers --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---