Generatore di plugin per 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 Mi Piace

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 Mi Piace

Yes would be better indeed.

3 Mi Piace

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 Mi Piace

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 Mi Piace

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.

Ho appena apportato un aggiornamento massiccio a questo.

Ne seguiranno altri: generatori specifici, ovvero aggiungere un controller, ad esempio, e plugin di amministrazione.

12 Mi Piace

Wow! Sembra ottimo dal diff (per qualcuno che sa pochissimo sulla scrittura di plugin). Non vedo l’ora di provarlo (ma probabilmente aspetterò di arrivare in ufficio lunedì :wink:)

2 Mi Piace

Ehi, @j.jaffeux, l’ho appena provato (e ho eseguito di nuovo un git pull, creando alcuni plugin aggiuntivi dopo che la prima volta non è andato a buon fine) e sto ricevendo

/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' non è un nome di controller supportato. Questo può causare problemi di routing. Vedi http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use (ArgumentError)

Sono dispiaciuto perché ho un plugin che è iniziato con questo, al quale ho aggiunto un sacco di codice prima di eseguirlo. Puoi dirmi come risolvere? Le informazioni presenti in quella guida e quelle che ho trovato su StackOverflow non mi aiutano.

Grazie.

Sì, ho incrociato questo altro problema e non l’ho ancora risolto.

Dovrebbe essere controllers/one_two/one_two_controller.rb, credo, ma non sono sicuro dato che non hai fornito tutti i dati.

4 Mi Piace

Sembra che l’abbia trovato! Il colpevole è in config/routes.rb. Ho modificato

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

in

get “/” => “three_four#index”, constraints: ThreeFourConstraint.new

e ora è tutto a posto, almeno a occhio mio ingenuo.

Come dovrei procedere?

Sto cercando di usarlo nel mio nuovo ambiente Deb Windows Subsystem
Il mio Discourse funziona ed è in esecuzione, ma quando provo a eseguire

rails g plugin --help

ottengo

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

L’esecuzione di bundle install non produce alcun risultato (nuovo) e precompiler è presente nell’elenco dei gem.
Idee?

Il tuo server Discourse è in esecuzione in un contenitore Docker? In tal caso, devi eseguire bundle install all’interno del contenitore.

No, non credo sia così. È un’istanza di sviluppo, è stato un clone diretto di git.

Questo ha funzionato perfettamente OOTB.

Grazie per questo.

Ho appena eseguito questo generatore di Rails e ho creato la struttura di base per un nuovo plugin, caricato su Git, aggiunto al file YAML, ricostruito l’app e si è installato senza problemi OOTB.

Ho visitato la scheda dei plugin ed ecco che c’era, completamente equipaggiata con una funzionalità di attivazione/disattivazione OOTB. :heart:

Grazie mille @j.jaffeux per questo generatore facile da usare e utile.

L’unica modifica che ho apportato è stata eseguire rm -rf sulla directory .git inclusa e re-init Git in modo da poterla spingere sul mio account; ma questo è probabilmente dovuto al fatto che non sono molto esperto di git e spesso devo colpire git things con un martello per farli funzionare come penso dovrebbero.

Generatore perfetto. Grazie ancora @j.jaffeux

4 Mi Piace

Sono contento che abbia funzionato per te. A dire il vero, dovrei dedicarci del tempo, dato che ci sono molte cose che non funzionano correttamente.

6 Mi Piace