Saving edits on user preferences page with required custom fields is unclear

I gave all existing users a value for the custom field:

users = User.where('NOT EXISTS(
                     SELECT 1
                     FROM user_custom_fields ucf
                     WHERE
                       ucf.user_id = users.id AND
                       ucf.name = ?
                  )', 'user_field_1')

users.each do |u|
  u.custom_fields['user_field_1'] = 'invited'
  u.save!
end
2 Mi Piace