Rails プラグインジェネレーター

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.

「いいね!」 5

There seems to be a mismatch between the plugin generator and this post. Specifically, the Beginner’s Guide suggests to create the javascript initializer with the following directory and naming structure:

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

However, the plugin creates the javascript initializer at

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?

「いいね!」 4

Yes would be better indeed.

「いいね!」 3

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

this thing breaks for me.

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

「いいね!」 6

I followed this tutorial 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.

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.

「いいね!」 2

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
to be very clear: I am just at the first page of this tutorial. specifically the part that links to this plugin generator.

I just made a massive update to this.

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

「いいね!」 12

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 :wink:)

「いいね!」 2

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

/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.

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

「いいね!」 4

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.

How should I go about this?

Trying to use this in my new Deb Environment Windows Subsystem
My Discourse works and runs, but when I try to run

rails g plugin --help

I get

/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.

Running bundle install doesn’t do anything (new) and precompiler is in the list of gems.
Ideas?

Is your Discourse server running in a Docker container? If so you need to run bundle install inside the container.

No I don’t think so its a development instance to it was a direct git clone

これは最初から完璧に動作しました。

ありがとうございます。

この Rails ジェネレーターを実行して、新しいプラグインの基本的な構造を作成し、Git にアップロードし、YML に追加してアプリを再構築したところ、最初から問題なくインストールされました。

プラグインタブにアクセスすると、最初から有効化/無効化設定が備わった状態で表示されました。:heart:

使いやすく便利なこのジェネレーターを提供してくださった @j.jaffeux さんに心から感謝します。

私が行った唯一の変更は、含まれていた .git ディレクトリを rm -rf で削除し、Git を再初期化して自分のアカウントにプッシュできるようにしたことです。ただし、これはおそらく私が git にあまり詳しくなく、意図した通りに動作させるために git things にハンマーで叩きつけていることが多いためでしょう。

完璧なジェネレーターです。改めてありがとうございます、@j.jaffeux

「いいね!」 4

お役に立てて嬉しいです。正直に言うと、まだ正しく動作していないことがたくさんあるので、それに時間を割くべきですね。

「いいね!」 6