# Rails plugin generator

**URL:** https://meta.discourse.org/t/rails-plugin-generator/95907
**Category:** Announcements
**Created:** [8월 29, 2018, 11:43오전 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907 "2018-08-29T11:43:01Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Tgr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgr/32/103367_2.png) [@Tgr](https://meta.discourse.org/u/Tgr)
#### Post date: [1월 7, 2019, 4:25오전 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/24 "2019-01-07T04:25:05Z")

</div>

Newbie note: you must run the generator in the Discourse source directory (that’s `/src` if you use Docker). Otherwise you’ll just get confusing error/help messages about how the parameters are incorrect for `rails new`.

---

<div class="post-metadata">

### Author: ![permacultureProgram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/permacultureprogram/32/108924_2.png) [@permacultureProgram](https://meta.discourse.org/u/permacultureProgram)
#### Post date: [3월 16, 2019, 10:03오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/25 "2019-03-16T22:03:08Z")

</div>

There seems to be a mismatch between the plugin generator and [this post](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515). Specifically, the **Beginner’s Guide** suggests to create the javascript initializer with the following directory and naming structure:

```plaintext
plugins/basic-plugin/assets/javascripts/discourse/initializers/alert.js.es6

```

However, the plugin creates the javascript initializer at

```plaintext
plugins/discourse-racoon/assets/javascripts/initializers/discourse-racoon.es6

```

Personally, I was having issues with the javascript loading after using this plugin until I changed the directory and naming structure to match the **Beginner’s guide**. Should the package be updated?

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [3월 16, 2019, 10:04오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/26 "2019-03-16T22:04:05Z")

</div>

Yes would be better indeed.

---

<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: [3월 16, 2019, 11:44오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/27 "2019-03-16T23:44:51Z")

</div>

Yes I had to rename the JavaScript extensions but the structure worked for me.

---

<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: [6월 24, 2019, 2:42오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/28 "2019-06-24T14:42:13Z")

</div>

this thing breaks for me.

 ![discourseplugingen](https://global.discourse-cdn.com/meta/original/3X/c/a/ca809d83225ad19b7483cf1b9d37fe821decffa8.png)

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [6월 24, 2019, 2:43오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/29 "2019-06-24T14:43:29Z")

</div>

Cant help you, you give me no context. What did you type? where did you type it? clean or exisisting state?

---

<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: [6월 24, 2019, 3:39오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/30 "2019-06-24T15:39:00Z")

</div>

I followed this tutorial [https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515). Just installed and worked so guess its clean.  
I typed:

> bundle exec rails g plugin cidian

EDIT: Capitalization matters in ruby. The name of the plugin created by this generator gets to be a ruby class so that’s why a lower case argument supplied to this generator will lead to a broken plugin.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [6월 24, 2019, 3:44오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/31 "2019-06-24T15:44:50Z")

</div>

> [@spirobel](#):
>
> Just installed and worked so guess its clean

No it’s not clean as you have followed this tutorial to create a plugin, and the error is likely in what you typed while following the tutorial.

The error is very clear to me: `mount ::cidian::Engine, at: "/cidian"` is invalid. You should fix this in your code.

---

<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: [6월 24, 2019, 3:48오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/32 "2019-06-24T15:48:44Z")

</div>

First of all: I dont know ruby (yet) as I will start from the front end.  
this code was produced by this plugin generator. so its not my fault. Its the generators fault. I typed nothing while following the tutorial. I just followed the development environment setup guide for ubuntu. Before running the generator the local discourse instance worked fine.  
[https://github.com/discourse/discourse/blob/master/lib/generators/plugin/templates/plugin.rb.erb](https://github.com/discourse/discourse/blob/master/lib/generators/plugin/templates/plugin.rb.erb)  
to be very clear: I am just at the first page of this tutorial. specifically the part that links to this plugin generator.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [7월 27, 2019, 4:22오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/33 "2019-07-27T16:22:48Z")

</div>

I just made a massive update to this.

[https://github.com/discourse/discourse/commit/d83f99fc2ec97fcab3a0d50f751ae96ff32eae96](https://github.com/discourse/discourse/commit/d83f99fc2ec97fcab3a0d50f751ae96ff32eae96)

More to come: specific generators AKA add one controller for example, and admin plugins.

---

<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: [7월 27, 2019, 4:54오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/34 "2019-07-27T16:54:49Z")

</div>

Wow! Looks great from the diff (to someone who knows very little about writing plugins). Can’t wait to try it out (but I likely will wait until I get to the office on Monday 😉)

---

<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: [8월 6, 2019, 12:31오전 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/35 "2019-08-06T00:31:38Z")

</div>

Hey, @j.jaffeux, I just tried it (and did a git pull again and created some more plugins with it after it failed the first time) and I’m getting

```plaintext
/home/pfaffman/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/mapper.rb:314:in `block (2 levels) in check_controller_and_action': 'one_two/one-two' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use (ArgumentError)

```

I’m sad because I have a plugin that started with this that I added a bunch of code to before running it. Can you tell me how to fix it? The stuff at that guide and what I found at StackOverflow don’t help me.

Thanks.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [8월 6, 2019, 6:22오전 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/36 "2019-08-06T06:22:58Z")

</div>

oh yes I stumbled on this this other and have yet to fix.

It should be `controllers/one_two/one_two_controller.rb` I think, not sure given you don’t give all the data

---

<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: [8월 6, 2019, 5:35오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/37 "2019-08-06T17:35:57Z")

</div>

It looks like I found it! The culprit is in `config/routes.rb`. I changed

```
 get "/" => "three-four#index", constraints: ThreeFourConstraint.new

```

to

get “/” =\> “three\_four#index”, constraints: ThreeFourConstraint.new

and all is well, at least to my naive eye.

---

<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: [8월 30, 2019, 9:58오전 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/38 "2019-08-30T09:58:15Z")

</div>

> [@Rails plugins vs discourse plugins - what is the difference?](https://meta.discourse.org/t/rails-plugins-vs-discourse-plugins-what-is-the-difference/127109/):
>
> 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 En…](https://guides.rubyonrails.org/engines.html)

How should I go about this?

---

<div class="post-metadata">

### Author: ![Jose\_C\_Gomez](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jose_c_gomez/32/137297_2.png) [@Jose\_C\_Gomez](https://meta.discourse.org/u/Jose_C_Gomez)
#### Post date: [10월 18, 2019, 3:34오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/39 "2019-10-18T15:34:00Z")

</div>

새로 만든 Deb 환경인 Windows Subsystem에서 이걸 사용하려고 합니다.  
Discourse는 정상적으로 작동하지만, 다음을 실행하려고 하면

```plaintext
rails g plugin --help

```

아래와 같은 오류가 발생합니다.

```plaintext
/var/lib/gems/2.5.0/gems/railties-6.0.0/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /home/jose/.rbenv/shims in PATH, mode 040777
Could not find actionview_precompiler-0.2.1 in any of the sources
Run `bundle install` to install missing gems.

```

`bundle install`을 실행해도 아무런 반응이 없고(새로 설치되는 것도 없음), precompiler는 이미 gem 목록에 있습니다.  
해결 방법이 있을까요?

---

<div class="post-metadata">

### Author: ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)
#### Post date: [10월 18, 2019, 4:20오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/40 "2019-10-18T16:20:26Z")

</div>

> [@Jose\_C\_Gomez](#):
>
> `bundle install`을 실행해도 아무 일이 일어나지 않습니다(새로 설치되지 않음). 또한 precompiler가 gems 목록에 있습니다.  
> 아이디어가 있으신가요?

Discourse 서버를 Docker 컨테이너에서 실행하고 계신가요? 그렇다면 컨테이너 _안에서_ `bundle install`을 실행해야 합니다.

---

<div class="post-metadata">

### Author: ![Jose\_C\_Gomez](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jose_c_gomez/32/137297_2.png) [@Jose\_C\_Gomez](https://meta.discourse.org/u/Jose_C_Gomez)
#### Post date: [10월 18, 2019, 4:21오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/41 "2019-10-18T16:21:10Z")

</div>

아니요, 그렇게 생각하지 않습니다. 개발 인스턴스이고 직접 git clone한 것이기 때문입니다.

---

<div class="post-metadata">

### Author: ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)
#### Post date: [4월 29, 2020, 2:12오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/42 "2020-04-29T14:12:17Z")

</div>

이것이 OOTB(Out Of The Box) 상태에서 완벽하게 작동했습니다.

감사합니다.

이 레일즈 생성기를 실행하여 새 플러그인의 기본 구조를 만들고, git에 업로드한 뒤 yml 파일에 추가하고 앱을 다시 빌드했는데, OOTB 상태에서 완벽하게 설치되었습니다.

플러그인 탭을 방문했는데, OOTB 활성화/비활성화 설정이 포함된 채로 그대로 있었습니다. ❤

이렇게 사용하기 쉽고 유용한 생성기를 만들어 주셔서 @j.jaffeux 님께 진심으로 감사드립니다.

제가 한 유일한 변경 사항은 포함된 `.git` 디렉터리에 `rm -rf`를 실행하고 git을 `재초기화`하여 제 계정에 push할 수 있도록 한 것입니다. 하지만 그것은 아마도 제가 `git`에 대해 매우 숙련되지 않아서, 제가 원하는 대로 작동하도록 `git 관련 작업`을 해머로 때려야 하는 경우가 많기 때문일 것입니다..

완벽한 생성기입니다. 다시 한번 감사합니다 @j.jaffeux

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [4월 29, 2020, 2:32오후 UTC](https://meta.discourse.org/t/rails-plugin-generator/95907/43 "2020-04-29T14:32:18Z")

</div>

그게 해결되었다니 다행입니다. 솔직히 말하면, 제대로 작동하지 않는 부분이 많아서 제가 시간을 투자해서 해결해야 할 것 같습니다.

[Previous page](https://meta.discourse.org/t/rails-plugin-generator/95907.md?page=1)

[Next page](https://meta.discourse.org/t/rails-plugin-generator/95907.md?page=3)
