Repro steps:
- Let’s create a user field and it has id
1
. - Run the second line of the below code twice.
Case 1
up = UserUpdater.new(Discourse.system_user, User.find(1))
up.update({:custom_fields=>{:user_field_1=>"abc"}})
- You’ll see
abc
twice when you go to/my/preferences/profile
Surprisingly, when the profile is updated via /my/preferences/profile
, it does so perfectly fine.
Case 2
This seems to work fine
up = UserUpdater.new(Discourse.system_user, User.find(1))
params = ActionController::Parameters.new({:custom_fields=>{:user_field_1=>"abc"}})
up.update(params.permit!)
What happens is, in Case 1, the value is pushed to an array and is displayed as comma-separated values on /my/preferences/profile
.
Case 2 seems to do the correct thing i.e. it replaces the current value with the new one but wrapping it in ActionController::Parameters
is unnatural.
https://github.com/discourse/discourse/blob/3e49c5b4d875654f3357583828086fe8fee104be/app/controllers/users_controller.rb#L160