I'm trying to use the #update_all method to bulk update a huge amount of data at high speed in a rake task. I have to update the email and phone fields. For the phone field is easy to set to "00000000000". In the email field i want to take the name stored in first_name field and add "@email.com". I've been trying things like this:
User.update_all(email: "#{User.first_name}"+"@email.com", phone: "00000000000")
But it doesn't work. Any ideas?
User.update_all("email = first_name || '@email.com', phone = '00000000000'")
|| will concatenate strings. The first name of each user will be concatenated with the @email.com and assign to the email field.
||
1.4m articles
1.4m replys
5 comments
56.9k users