4

I'm new on both this site and ruby on rails! I have a common installation of authlogic and want password to be generated automaticly for user registration if user did not set the password. What is the best way to do it?

tshepang
  • 12,111
  • 21
  • 91
  • 136
vooD
  • 2,881
  • 2
  • 25
  • 34

1 Answers1

4

The solution is:

#app/models/User.rb
class User < ActiveRecord::Base
#...
  before_validation_on_create { |record| record.randomize_password unless record.password }
#...
end
vooD
  • 2,881
  • 2
  • 25
  • 34