# Générateur de plugin Rails

**URL:** https://meta.discourse.org/t/rails-plugin-generator/95907
**Category:** Announcements
**Created:** [Août 29, 2018, 11:43 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907 "2018-08-29T11:43:01Z")
**Posts on this page:** 1
**Showing post:** 19

<div class="post-metadata">

### Author: ![joebuhlig](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joebuhlig/32/193054_2.png) [@joebuhlig](https://meta.discourse.org/u/joebuhlig)
#### Post date: [Août 31, 2018, 1:20 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/19 "2018-08-31T13:20:59Z")

</div>

I just finished creating a public version of this. That way others can use it as well and I can share links to specifics since I realized there are some more points that I do.

[https://github.com/procourse/discourse-plugin-template](https://github.com/procourse/discourse-plugin-template)

- Whenever I add custom routes to a plugin, I always use a [Constraint](https://github.com/procourse/discourse-plugin-template/blob/master/lib/discourse_plugin_template_constraint.rb) that ties to the plugin enabled setting. This prevents the [routes from existing](https://github.com/procourse/discourse-plugin-template/blob/master/config/routes.rb#L4) unless the site setting is true. I wish I saw this more in plugins as custom routes shouldn’t be allowed just because the plugin is installed.

- This template includes a [Rails controller](https://github.com/procourse/discourse-plugin-template/blob/master/app/controllers/discourse-plugin-template/hello_controller.rb) and an [Ember route](https://github.com/procourse/discourse-plugin-template/blob/master/assets/javascripts/discourse/discourse-plugin-template-route-map.js.es6). These are only used in about half of the plugins I do, but it’s nice to have them there just so the structure already exists. I don’t know that this generator needs to include these pieces, but it’s helpful on my end.

- I always start my stylesheets with a [global class selector](https://github.com/procourse/discourse-plugin-template/blob/master/assets/stylesheets/discourse-plugin-template.scss). Every time I add HTML to the plugin, I start with a wrapper `div` with `class="discourse-plugin-template"`. That ensures that my styles only apply to my custom code. Sometimes I need to add CSS outside of that selector, but it seems like most cases don’t have that requirement.

---

_[View the full topic](https://meta.discourse.org/t/rails-plugin-generator/95907)._
