# Rails 콘솔에서 사용자 정의 필드 조작하기

**URL:** <https://meta.discourse.org/t/manipulating-custom-user-fields-from-the-rails-console/218613>\
**Category:** Development\
**Tags:** rails-console, user-custom-fields\
**Created:** [2월 17, 2022, 9:12오후 UTC](https://meta.discourse.org/t/manipulating-custom-user-fields-from-the-rails-console/218613 "2022-02-17T21:12:08Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)\
**Post date:** [2월 17, 2022, 9:12오후 UTC](https://meta.discourse.org/t/manipulating-custom-user-fields-from-the-rails-console/218613/1 "2022-02-17T21:12:08Z")

</div>

이 코드 스니펫을 사용하여 사용자 사용자 정의 필드에서 일부 데이터를 일괄 치환하려고 했습니다. 이 코드는 [Ning 가져오기 스크립트](https://github.com/discourse/discourse/blob/main/script/import_scripts/ning.rb)에서 가져왔습니다.

```plaintext
users=User.where("users.created_at <= '2019-09-13'::timestamp")
users.each do |u|
  u.custom_fields = {"user_field_16" => "Nil"}
  u.save
end

```

그러나 의도치 않은 결과로 사용자들의 _다른_ 사용자 정의 필드 값들이 모두 지워졌습니다.

혼란을 일으키지 않고 콘솔에서 사용자 사용자 정의 필드 값을 수정하는 방법에 대해 조언을 주실 수 있는 분이 계신가요?

---

_[View the full topic](https://meta.discourse.org/t/manipulating-custom-user-fields-from-the-rails-console/218613)._
