# Rails plugins vs discourse plugins - what is the difference?

**URL:** https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109
**Category:** Development
**Created:** [August 29, 2019, 12:15pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109 "2019-08-29T12:15:42Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [August 29, 2019, 12:15pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/1 "2019-08-29T12:15:42Z")

</div>

I want to make a plugin that needs its own tables. So its a good idea to have migration and model generators, because manually copying them from the main app dir will lead to errors and is just not very convenient. So I started making my own generators. I started with the migration generator:  
[https://github.com/spirobel/discourse/commit/3ba8190286b5c40eeace1b58238cbf5075db597e](https://github.com/spirobel/discourse/commit/3ba8190286b5c40eeace1b58238cbf5075db597e)  
I could move on now and do the same for models and controllers. But now I started to read this [Getting Started with Engines — Ruby on Rails Guides](https://guides.rubyonrails.org/engines.html) and now it seems to me that all of this might be a duplication of efforts. Why does the [discourse plugin generator](https://meta.discourse.org/t/rails-plugin-generator/95907) diverge so much from the rails plugin generator?  
The rails plugin generator makes a plugin specific ` bin/rails` that enables the plugin specific migration and model generators. It would be nice to have something like this as well. I tried to make something like this as well but I could not get it to work, so I went the other route and just started creating these special snowflake generators. If I understood better what the differences between the rails and the discourse way of making plugins is, I might be able to go this other route which might save time. Maybe someone can expand on this. Why are discourse and rails plugins something different and why do they not build on each other?

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 29, 2019, 12:20pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/2 "2019-08-29T12:20:06Z")

</div>

Rails plugins are different from Discourse plugins due to many reasons. Discourse plugins need to have a specific folder structure, they can extend/override the ember code of the core discourse etc. I think the rails side of a discourse plugin would be closer to a generic rails plugin but they aren’t the same things.

Moreover, one should only create new tables if they’re really needed. Discourse already has ~150 tables and its not too often that your job isn’t done using one or a couple of them.

But, moving forward, I personally would wish and like to see that happen. It would mean people are building huge and more exciting plugins and getting more creative with what could be done with Discourse.

---

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [August 29, 2019, 12:30pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/3 "2019-08-29T12:30:41Z")

</div>

> [@fzngagan](#):
>
> Moreover, one should only create new tables if they’re really needed. Discourse already has ~150 tables and its not too often that your job isn’t done using one or a couple of them.

I need them. Even basic functionality needs tables. I think its really annoying that there is no clear documented way on how to do this. For example the poll plugin uses its own tables, but I cant find the generator for how to make them. [discourse/plugins/poll at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/tree/master/plugins/poll)  
Another benefit from documenting is that there will be conventions on table/migration namespacing. (I saw some really hacky solutions recommended here in the forums on how to add migrations to a plugin)

> [@fzngagan](#):
>
> But, moving forward, I personally would wish and like to see that happen. It would mean people are building huge and more exciting plugins and getting more creative with what could be done with Discourse.

Nice! So which way to go? moving closer to the rails plugin generator with own `bin/rails` in the plugin folder, or own versions for all the generators (migrations/models/controllers) ?

---

<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: [August 29, 2019, 12:39pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/4 "2019-08-29T12:39:36Z")

</div>

You need to read the plugin development howto topics here. For most plugins you can use existing tables (like post custom field). There are times that you need more tables, but you’d probably do well to start with something less difficult to start.

---

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [August 29, 2019, 1:00pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/5 "2019-08-29T13:00:21Z")

</div>

> [@pfaffman](#):
>
> You need to read the plugin development howto topics here.

I read the beginners plugin guide and [this](https://meta.discourse.org/t/how-to-start-building-stuff-for-discourse-if-youre-newbie-like-myself/45954) . Is there something else? I also looked at the code of some plugins. I just know that I need tables. And there are other plugins as well that use their own tables. Why is there this obsession with not creating new tables? Is there a big cost involved with creating new tables? Especially if they are namespaced with the plugin name at the beginning I really dont see the downside.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 29, 2019, 1:04pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/6 "2019-08-29T13:04:14Z")

</div>

[https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827/19?u=fzngagan](https://meta.discourse.org/t/creating-routes-in-discourse-and-showing-data/48827/19)

> [@How can I make my own Discourse plugins?](https://meta.discourse.org/t/how-can-i-make-my-own-discourse-plugins/90032/2):
>
> I’ve only just started but here’s my ‘starter for 10’ to get you going: Read: [these](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515)[this](https://meta.discourse.org/t/how-to-start-building-stuff-for-discourse-if-youre-newbie-like-myself/45954) Try and read the code on the simplest, [but popular plugins](https://meta.discourse.org/c/plugin/l/top/yearly) and see if you can understand what they are doing (this is not always easy, especially with the complexity of dealing with multiple files and the sometimes brutal functional brevity of javasctipt, but persevere) You need to learn: Lots of Javascript (look no further than @mpj’s [Fun Fun Function excellent & fun (!) videos](https://www.youtube.com/channel/UCO1cgjhGzsSYb1rsB4bFe4Q) (thanks man!)) Lots of …

These ones here. I highly recommend these ones hands on before making any comment about anything related to dev. Not to say you might not need custom tables ever but these are must anyway.

---

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [August 29, 2019, 1:23pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/7 "2019-08-29T13:23:53Z")

</div>

> <https://github.com/discourse/discourse/blob/888e68a1637ca784a7bf51a6bbb524dcf7413b13/app/models/plugin_store.rb>

this thing is just a basic key value store. I cant store relations between tables there. I like SQL. And I need to use it for the plugin I want to create.

> [@How to create migration files?](https://meta.discourse.org/t/how-to-create-migration-files/48991/3):
>
> Note that if you are developing a plugin, discourse provides a PluginStore to help you avoid migrations, since undoing then when the plugin gets uinstalled is a open problem.

I can understand this problem applies to people that want to create plugins that “non technical people” can install and uninstall. I am not one of those people. So I would be glad if we could go back to the topic.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [August 29, 2019, 8:16pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/8 "2019-08-29T20:16:34Z")

</div>

> [@spirobel](#):
>
> I can understand this problem applies to people that want to create plugins that “non technical people” can install and uninstall. I am not one of those people.

If the intent is to create something only you yourself will be using, IMHO it would likely be better to write a browser extension or a desktop app instead of a plugin. Any reason this must be a plugin?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [August 30, 2019, 6:14pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/9 "2019-08-30T18:14:38Z")

</div>

Here’s an interesting related discussion:

> [@Adding jsonb columns for custom fields](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418):
>
> Often times when developing plugins, I’ve had to use the CustomField or PluginRowStore tables to store arbitrary data related to the plugin (for example, [retort](https://meta.discourse.org/t/retort-a-reaction-style-plugin-for-discourse/35903) stores a string representation of reactions to a particular post as a PostCustomField) This works well for simple data, but for anything a bit more complex, I’ve found myself wanting access to more than a postgres text-valued column can provide. Postgres has supported the jsonb column type for several versions now ([since 9.4](https://www.postgresql.org/docs/9.4/static/datatype-json.html)), which pro…

---

<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: [March 24, 2023, 11:53pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/10 "2023-03-24T23:53:30Z")

</div>



---

<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: [March 27, 2023, 1:00pm UTC](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/11 "2023-03-27T13:00:54Z")

</div>

This topic was automatically closed after 2 days. New replies are no longer allowed.
