If you have your validations set, you can use something like
in User model:
scope :without_username, where(:username => nil)
validates :username, :uniqueness => true, :presence => false
and then use
users = User.without_username
users.each do |user|
username = user.email.split(/@/).first
user.username = username
while !user.valid?
user.username+=rand(10).to_s
end
user.save
end
tom
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/4tkg3bBKTbcJ.
> To post to this group, send email to
rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en-US.
--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz
===============================================================================