# Wijzig chatkanaal gekoppelde categorie in Rails console?

**URL:** <https://meta.discourse.org/t/change-chat-channel-linked-category-in-rails-console/327361>\
**Category:** Support\
**Created:** [20 september 2024 om 06:17 UTC](https://meta.discourse.org/t/change-chat-channel-linked-category-in-rails-console/327361 "2024-09-20T06:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Magie](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Magie](https://meta.discourse.org/u/Magie)\
**Post date:** [20 september 2024 om 06:17 UTC](https://meta.discourse.org/t/change-chat-channel-linked-category-in-rails-console/327361/1 "2024-09-20T06:17:28Z")

</div>

Dear Discourse community,

it is not possible in the UI to change the category which is linked to a chat channel. I need to move a chat to a different category.

I am wondering if this is possible through the Rails console or would it break something?

Any hints on how to go about it and experiences are welcome.

---

<div class="post-metadata">

**Author:** ![Magie](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Magie](https://meta.discourse.org/u/Magie)\
**Post date:** [2 december 2024 om 15:23 UTC](https://meta.discourse.org/t/change-chat-channel-linked-category-in-rails-console/327361/2 "2024-12-02T15:23:38Z")

</div>

**Update:**  
I figured out my solution and sharing it here since it might help somebody.

**Disclaimer:**  
You need access to your server and it helps if you understand what you’re doing. If not, I recommend getting help from somebody who knows servers and Ruby on Rails.  
Also be mindful: Changing data in a running database could cause problems.

**Steps:**  
First access your server. Once you’re there become a root user. Navigate to the Discourse container and enter it:

```plaintext
cd /var/discourse
./launcher enter app

```

Once inside the container open the Rails console:

```plaintext
rails c

```

Now in your browser find the chat channel slug. You can find it inside the URL e.g. when you open the chat channel in full screen mode:  
`https://my-example-forum.com/chat/c/cat-pictures/17`

In the Rails console get the chat channel object you want and save it in a variable:

```plaintext
chat = Chat::Channel.find_by(slug: "cat-pictures")

```

If now you just type the variable `chat` and hit enter you can see the object and all its attributes. One of it is `chatable_id`. There you can see the ID of the category the chat channel is linked to. The `chatable_id` could be set to 5 for example.

We can change this chatable\_id to the ID of the category you want the chat channel to correspond to. You can find this ID in the URL of the category in the browser:  
`https://my-example-forum.com/c/cats/9`

Now that you know the desired category ID you can adjust the category linked to the chat channel:

```plaintext
chat.chatable_id=9
chat.save

```

I hope this helps.

* * *

Might also be relevant for [How change a Chat Channel's category that it's linked to](https://meta.discourse.org/t/how-change-a-chat-channels-category-that-its-linked-to/257122)

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [1 januari 2025 om 15:24 UTC](https://meta.discourse.org/t/change-chat-channel-linked-category-in-rails-console/327361/3 "2025-01-01T15:24:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
