# Controllers and Routes

**URL:** https://meta.discourse.org/t/controllers-and-routes/376468
**Category:** Development
**Created:** [July 29, 2025, 7:11pm UTC](https://meta.discourse.org/t/controllers-and-routes/376468 "2025-07-29T19:11:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![itd-john](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@itd-john](https://meta.discourse.org/u/itd-john)
#### Post date: [July 29, 2025, 7:11pm UTC](https://meta.discourse.org/t/controllers-and-routes/376468/1 "2025-07-29T19:11:24Z")

</div>

When following the [tutorial for setting up a custom controller](https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827) and route, I get the Routing Error page. The page lists the paths and controllers, which is all correct however, when I request the resource, I get errors. I understand this is an old tutorial but, is the information accurate? I’ve attached my plugin skeleton and maybe someone can help trouble shoot the issue. Thanks!

[jb-test.zip](https://meta.discourse.org/uploads/short-url/ylJGRptL7NDp9gbqNVgU6ciWDgf.zip) (522.2 KB)

---

<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: [July 29, 2025, 8:25pm UTC](https://meta.discourse.org/t/controllers-and-routes/376468/2 "2025-07-29T20:25:52Z")

</div>

I think the thing you’re missing is to add it to rails routing.

Something like this in `plugin.rb`.

```plaintext
  JbTest::Engine.routes.draw do
    get "/hello" => "jbtest#index"
  end

```

Here’s a start. The other thing to do is to get [GitHub - discourse/all-the-plugins · GitHub](https://github.com/discourse/all-the-plugins) and look through there. Now that so many have been added to core, though, I suppose you could just look there for examples of added to the Rails route.

> **Minimal Custom Route Plugin for Discourse
AI**
>
> **pfaffman:**
> 
> what’s needed to add a route to Discourse rails?
> 
> Can you give me a minimal proof of concept that includes a plugin.rb, and controller, and the stuff needed to add the route to rails?
> 
> **DiscourseHelper:**
> 
> > **Searching**
> >
> > Searching for: How to add a custom route to Discourse using a plugin, including a minimal example with plugin.rb, custom controller, and the necessary code to register the Rails route?
> 
> > **Reading**
> >
> > Read: [Developing Discourse Plugins - Part 1 - Create a basic plugin](https://meta.discourse.org/t/developing-discourse-plugins-part-1-create-a-basic-plugin/30515)
> 
> > **Searching**
> >
> > Searching for: Minimal proof of concept for adding a custom Rails route in Discourse plugin including plugin.rb, controller implementation, and code to register the route.
> 
> > **Reading**
> >
> > Read: [Creating Routes in Discourse and Showing Data](https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827)
> 
> > **Reading**
> >
> > Read: [Add custom user routes using plugins](https://meta.discourse.org/t/add-custom-user-routes-using-plugins/102620)
> 
> > **Reading**
> >
> > Read: [Adding a ruby controller via plugin](https://meta.discourse.org/t/adding-a-ruby-controller-via-plugin/60661)
> 
> Here’s a minimal proof of concept for adding a custom Rails route to Discourse via a plugin, including the key files you’ll need: `plugin.rb`, a controller, and the code for registering the route.
> 
> **Key Points**
> 
> - The best practice is to use a Rails “engine” within your plugin to isolate your controllers and routes.
> - You need to explicitly require your controller in `plugin.rb`.
> - To register a new route, you use the engine’s `routes.draw` method and mount the engine in the main application routes.
> 
> **Minimal Example**
> 
> **plugin.rb**
> 
> ```ruby
> # name: my-custom-route
> # about: Adds a custom route via Rails engine in a plugin
> # version: 0.1
> # authors: Your Name
> 
> after_initialize do
> module ::MyPlugin
> class Engine < ::Rails::Engine
> engine_name "my_plugin"
> isolate_namespace MyPlugin
> end
> end
> 
> require_dependency File.expand_path('../app/controllers/my_plugin/my_controller.rb', __FILE__ )
> 
> MyPlugin::Engine.routes.draw do
> get "/hello" => "my#hello"
> end
> 
> Discourse::Application.routes.append do
> mount ::MyPlugin::Engine, at: "/my_plugin"
> end
> end
> 
> ```
> 
> **app/controllers/my\_plugin/my\_controller.rb**
> 
> ```ruby
> module MyPlugin
> class MyController < ::ApplicationController
> def hello
> render plain: "Hello from my plugin!"
> end
> end
> end
> 
> ```
> 
> **How this works:**
> 
> - `GET /my_plugin/hello` will return the plain text response `"Hello from my plugin!"`.
> 
> **Required Directory Structure:**
> 
> ```plaintext
> plugins/
> my-custom-route/
> plugin.rb
> app/
> controllers/
> my_plugin/
> my_controller.rb
> 
> ```
> 
> **For more details and expanded examples, see:**
> 
> - [Creating Routes in Discourse and Showing Data](https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827)
> - [Adding a ruby controller via plugin](https://meta.discourse.org/t/adding-a-ruby-controller-via-plugin/60661)
> - [Add custom user routes using plugins](https://meta.discourse.org/t/add-custom-user-routes-using-plugins/102620)
> 
> This proof of concept will help you add a simple custom endpoint to your Discourse instance via a plugin. If you have questions about integrating this with Ember/JS side, let me know!

---

<div class="post-metadata">

### Author: ![itd-john](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@itd-john](https://meta.discourse.org/u/itd-john)
#### Post date: [July 29, 2025, 9:51pm UTC](https://meta.discourse.org/t/controllers-and-routes/376468/3 "2025-07-29T21:51:24Z")

</div>

OK. Thank you. It looks like that bit of code was added to routes.rb but, I’ll look through the core plugins and see if I can find an example in plugins.rb. Thanks!
