Manipulating Custom User Fields from the Rails Console
The original poster, nathank, attempted to bulk replace data in a user custom field using a code snippet derived from the Ning importer. However, this resulted in wiping the users’ other custom field values.
JammmyDodger suggested a modified version of the code that only changes the specified custom field, using u.custom_fields["user_field_16"] = "Nil" instead of u.custom_fields = {"user_field_16" => "Nil"}.
fzngagan explained that the original code replaced the entire u.custom_fields hash, which is why other custom field values were lost.
nathank confirmed that using u.custom_fields["user_field_16"] = "Nil" was the correct approach.
pfaffman offered alternative methods for creating or updating custom fields using UserCustomField.create and UserCustomField.find_by.
nathank shared a useful tool for getting the Rails syntax right when manipulating custom fields in the Rails console, including a placeholder template for replacing or filling custom field data.
Other users, including j127 and Kuro22, discussed the dynamic content in the post, with Kuro22 linking to a meta post about placeholder forms.
and then you’d need to either update it or create a new one.
But if you do create multiple ones, the UX will show them comma-separated, and if they are edited via the UX when they get saved, they get saved back to a single value.
You can have a look at them with
UserCustomField.all
Or
UserCustomField.where(name: x)
That’s by memory on my phone so your mileage may vary.