i''m using the authentication chapter in the rails recipes book to help me out, but i ran into a snag... it uses password_hash and password_salt as the fields for storing the database info. but in the model, there is a password=(pass) method that does the work for generating the salt and the encryption. since "password" isn''t one of the database fields, i''m having validation problems. i have a ''validates_presence_of'' for the password method which works fine, but my problem comes when i am updating a User record that doesn''t have a password field in the form. i am still getting the "password can''t be blank" error. what''s the best workaround for this so i can only use the validations on "password" when i am updating the password. i hope that makes sense... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is a great article: http://www.aidanf.net/rails_user_authentication_tutorial It does authentications like the rails recipe but it explains the validation process for password. I implemented authentication by following this article and it worked great. Hope that helps - K On Feb 20, 2:26 pm, "Josh" <jjkie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i''m using the authentication chapter in the rails recipes book to help > me out, but i ran into a snag... > > it uses password_hash and password_salt as the fields for storing the > database info. but in the model, there is a password=(pass) method > that does the work for generating the salt and the encryption. > > since "password" isn''t one of the database fields, i''m having > validation problems. i have a ''validates_presence_of'' for the password > method which works fine, but my problem comes when i am updating a > User record that doesn''t have a password field in the form. i am still > getting the "password can''t be blank" error. > > what''s the best workaround for this so i can only use the validations > on "password" when i am updating the password. > > i hope that makes sense...--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
actually that did help out alot. i didn''t find the answer i was looking for in the article, but someone had the same problem as i did in the comments and posted their solution. they just wanted validation to work if there was a password field in the form, like if they wanted to change just their name or email address. they put this in their model: validates_presence_of :password, :if => :password_required? and further down had something like this: protected def password_required? !password.nil? end i think i read that this is similar to the way that mephisto works. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Kim wrote:> This is a great article: > http://www.aidanf.net/rails_user_authentication_tutorial > It does authentications like the rails recipe but it explains the > validation process for password.That was very useful, thanks. It answered my question about the best place to put the password validation (i.e. in the user model, despite the password not being in the database). -- 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?hl=en -~----------~----~----~----~------~----~------~--~---