Generador de plugins para 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 Me gusta

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 Me gusta

Yes would be better indeed.

3 Me gusta

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 Me gusta

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 Me gusta

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.

Acabo de hacer una actualización masiva a esto.

Próximamente más: generadores específicos, es decir, añadir un controlador, por ejemplo, y plugins de administración.

12 Me gusta

¡Guau! Se ve genial en el diff (para alguien que sabe muy poco sobre cómo escribir complementos). ¡No puedo esperar a probarlo (pero probablemente esperaré hasta que llegue a la oficina el lunes :wink:))

2 Me gusta

Hola, @j.jaffeux, acabo de probarlo (y volví a hacer un git pull y creé algunos plugins más después de que fallara la primera vez) y estoy obteniendo:

/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' no es un nombre de controlador compatible. Esto puede provocar problemas de enrutamiento. Consulta http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use (ArgumentError)

Estoy triste porque tengo un plugin que comenzó con esto y le agregué mucho código antes de ejecutarlo. ¿Podrías decirme cómo solucionarlo? Lo que dice esa guía y lo que encontré en StackOverflow no me ayudan.

Gracias.

Sí, me encontré con esto en otra parte y aún no lo he solucionado.

Creo que debería ser controllers/one_two/one_two_controller.rb, aunque no estoy seguro ya que no proporcionas todos los datos.

4 Me gusta

¡Parece que lo encontré! El culpable está en config/routes.rb. Cambié

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

a

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

y todo está bien, al menos a mi ojo ingenuo.

¿Cómo debería proceder con esto?

Intento usar esto en mi nuevo entorno Debian para Windows Subsystem
Mi Discourse funciona y se ejecuta, pero cuando intento ejecutar

rails g plugin --help

recibo

/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
No se pudo encontrar actionview_precompiler-0.2.1 en ninguna de las fuentes
Ejecuta `bundle install` para instalar las gemas faltantes.

Ejecutar bundle install no hace nada (nuevo) y precompiler está en la lista de gemas.
¿Alguna idea?

¿Tu servidor Discourse se está ejecutando en un contenedor Docker? Si es así, necesitas ejecutar bundle install dentro del contenedor.

No, no creo que sea así. Es una instancia de desarrollo, así que fue un clon directo de Git.

Esto funcionó perfectamente OOTB.

Gracias por esto.

Acabo de ejecutar este generador de Rails y creé la estructura básica para un nuevo plugin, lo subí a Git, lo agregué al YAML, reconstruí la aplicación y se instaló sin problemas OOTB.

Visité la pestaña del plugin y allí estaba, totalmente equipada con una configuración de habilitar/deshabilitar OOTB. :heart:

Muchas gracias @j.jaffeux por este generador fácil de usar y útil.

El único cambio que hice fue ejecutar rm -rf en el directorio .git incluido y re-iniciar Git para poder subirlo a mi cuenta; pero eso probablemente fue porque no soy muy hábil con git y a menudo tengo que golpear las cosas de git con un martillo para que funcionen como creo que deberían.

Generador impecable. Gracias de nuevo @j.jaffeux

4 Me gusta

Me alegra que te haya funcionado. Para ser honesto, debería invertir tiempo en ello, ya que hay muchas cosas que no funcionan correctamente.

6 Me gusta