# How to make changes on backend side of discourse application using rails

**URL:** https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682
**Category:** Development
**Created:** [December 22, 2022, 5:05pm UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682 "2022-12-22T17:05:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kapil65](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kapil65](https://meta.discourse.org/u/kapil65)
#### Post date: [December 22, 2022, 5:05pm UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/1 "2022-12-22T17:05:44Z")

</div>

I make changes in discourse application where I want to show to topics according to number of replies, I created rails query but I am no able to find out the view part, Where I need to show and adding this scope.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 22, 2022, 7:24pm UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/2 "2022-12-22T19:24:09Z")

</div>

If you want to change how Discourse behaves, you’ll need to see [Developing Discourse Plugins - Part 1 - Create a basic plugin](https://meta.discourse.org/t/developing-discourse-plugins-part-1-create-a-basic-plugin/30515) or perhaps [Beginner’s guide to developing Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-developing-discourse-themes/93648).

---

<div class="post-metadata">

### Author: ![kapil65](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kapil65](https://meta.discourse.org/u/kapil65)
#### Post date: [December 23, 2022, 6:25am UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/3 "2022-12-23T06:25:36Z")

</div>

> [@pfaffman](#):
>
> ou’ll ne

I don’t want to create new plugin, I just want to change the category & topic queries from backend side and want to show on view, but Can’t find out where the list of topics link are shown.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [December 23, 2022, 7:09am UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/4 "2022-12-23T07:09:43Z")

</div>

> [@kapil65](#):
>
> I want to show to topics according to number of replies,

There is a category setting that might work for that:

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/6/6/a663fce5811cd0f133506630b2e5637c343c7272.png)

> [@kapil65](#):
>
> I don’t want to create new plugin, I just want to change the category & topic queries from backend side and want to show on view

If you need to change the code, you should make your changes in a plugin. Making changes to the core code will cause you problems in the future.

---

<div class="post-metadata">

### Author: ![kapil65](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kapil65](https://meta.discourse.org/u/kapil65)
#### Post date: [December 23, 2022, 7:59am UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/5 "2022-12-23T07:59:05Z")

</div>

Okay Simon, Thank you  
I think It will help me out

---

<div class="post-metadata">

### Author: ![kapil65](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kapil65](https://meta.discourse.org/u/kapil65)
#### Post date: [December 23, 2022, 10:59am UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/6 "2022-12-23T10:59:04Z")

</div>

I want to sort this right side links of topics for particular catgeory based on highest number of topics, It will need to change the modification on backend side right?

 ![Screenshot from 2022-12-23 16-27-09](https://global.discourse-cdn.com/meta/original/4X/8/4/2/8429aea44acab8450bb16eaddecf781aa861c38c.png)

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [December 23, 2022, 9:46pm UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/7 "2022-12-23T21:46:59Z")

</div>

I don’t think you need to modify code for this, but you may need to run a command from your site’s rails console to get the topics to display in the new order on your site’s homepage.

When you select “Categories with Featured Topics” for the `desktop category page style` site setting, the order that the featured topics are displayed in should be set by the value of each category’s “Topic List Sort By” setting. Unfortunately, if you make a change to a category’s “Topic List Sort By” setting, that change is not immediately shown on the site’s homepage. I am not sure where Discourse is caching the featured topics that are displayed on the home or what action is used by Discourse to trigger breaking the cache.

From testing on my own site, I see that the cache can be broken by running the following from the rails console:

```ruby
# Assign the category you want to fix the results for to a variable, for example:

c = Category.find(42)

# Then run
CategoryFeaturedTopic.feature_topics_for(c)

```

After running that, the topics should get displayed on the homepage in the order you selected for the category’s “Topic List Sort By” setting. I don’t think that running that command can cause any issues, but always be careful running commands from the rails console.

I’m sure there is an easier way to do this. Possibly you just need to wait for up to 24 hours for Discourse to break the cache on the old featured topic list. I’m not seeing where in the code the cache is broken. The relevant code seems to be here: [discourse/app/models/category\_featured\_topic.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/app/models/category_featured_topic.rb#L45).

---

<div class="post-metadata">

### Author: ![kapil65](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kapil65](https://meta.discourse.org/u/kapil65)
#### Post date: [December 26, 2022, 6:32am UTC](https://meta.discourse.org/t/how-to-make-changes-on-backend-side-of-discourse-application-using-rails/249682/8 "2022-12-26T06:32:16Z")

</div>

I hit that query but main problem is that where this featured topics are displayed on the home, on which .html file have code to shown this data on UI.  
I already made a queries for what data I need to sort but problem is where I put the query into which model.
