Discourse Plugins and Rails 6 config/initializers Question dev

This is describing a core Rails property, which is not germane to Discourse.

In Rails, all initializers are loaded only when Rails starts up, so any plugin which executes code based on the initializer, like "after_initializer" will only execute on Rails start up or restart (please correct me if wrong).

https://guides.rubyonrails.org/v2.3/configuring.html

The reason I am familiar with this is that I am currently building a Rails application for a client and I have written a lot of initializers for various tasks (booleans, static arrays, etc). In each case, if we change any code in a Rails initializer, it is necessary to restart Rails ("Control c, rails s in dev") to get the new values in the initializers into the Rails app.

Please correct me if I am wrong! Thanks.

Sometimes, I think it might be a bit confusing to some Discourse plugin developers, especially those developers who primarily work on Discourse plugins and not with Rails applications in general, when we write "Discourse does this" or "Discourse does that" when what we are really describing is a core Rails function or property not necessarily germane to Discourse, per se.

Rails 6 reads all files in the config/initializers directory (and all config/initializers subdirectories) only when Rails starts up. Likewise (not 100% sure about plugins) a Discourse plugin with code dependent on after_initialize will (kindly confirm anyone?) only be loaded by the Rails app when Rails starts up or restarts, because this is a fundamental property of the Rails boot process.

My guess is that everyone here already knows this who works on Rails. I only am starting to know these details (and feel I have a long way to go to be an expert); because I'm currently working on a Rails application every day (these days), which by-the-way, I now wish I would have starting working with Rails a decade ago because coming from a LAMP dev background, I find Rails so very much better (easy and fun to work with).

I have become a major Rails fan this year and I am very grateful to Discourse to starting me down that path.

Again, please correct me if I am wrong! Thanks. I'm trying to be more expert in Rails.

2 Likes