Manipulating custom user fields from the Rails console

I find this a useful tool for getting the rails syntax right when you want to manipulate these UCFs in the Rails console:

If you are replacing data in that field
UserCustomField.find_by(user_id: =UserID=, name: "=UserFieldName=").update(value: "=NewValue=")

(will give you an error if there isn’t any data in that field yet)

If you are filling that field for the first time
UserCustomField.create(user_id: =UserID=, name: "=UserFieldName=",value: "=NewValue=")
7 Likes