Hi,
I have been developing a Rails plugin recently, and I have realised
that for every change I make into files of my plugin, I have to
restart the server to make changes take effect. While changes at
application's own file appear instantly.
I'm writing only after I searched for an answer over web but didn't
find any. It's getting irritating now.
Hi,
I have been developing a Rails plugin recently, and I have realised
that for every change I make into files of my plugin, I have to
restart the server to make changes take effect. While changes at
application's own file appear instantly.
I'm writing only after I searched for an answer over web but didn't
find any. It's getting irritating now.
-thanks
I think it comes down to what type of plugin you are using first of all.
If the plugin communicates with a database or something that can change
dynamically then it can be done.
You can specify a configs environment with your plugin for how it
behaves via option types. Load those in a database and have an admin
page that changes the way it works there. I do this with a CMS plugin I
created for my site.
No, you didn't understand.
What I'm telling is, while I'm coding in "development" mode, if I
change something in "app/controllers/application_controller.rb",
changes appear instantly. But if I change something in "vendor/plugins/
my_plugin/lib/example.rb", I need to restart the server for changes to
take effect. (even in "development" mode).
In other words, applications files get reloaded on every request,
while plugin files load only once and stay in memory.
How can I make sure that plugin files also reload with every request?
I have this in my development.rb file, which I set up when I was making some changes to a thirdparty plugin and got sick of the constant restarting.
# this forces the Ezgraphix plugin to be reloaded each time - to facilitate 'fixing' and updating it
Dependencies.explicitly_unloadable_constants << 'Ezgraphix'
["ezgraphix"].each do |plugin_name|
reloadable_path = RAILS_ROOT + "/vendor/plugins/#{plugin_name}/lib"
Dependencies.load_once_paths.delete(reloadable_path)
end
Thanks Simon Macneall,
It worked!!
I hope you mean ActiveSupport::Dependencies by Dependencies otherwise
I get an error `const_missing':NameError: uninitialized constant
Rails::Initializer::Dependencies.
I first tried only to write
That's exactly what I was going to suggest. I have several lib files I
develop parsers with and other app factorization methods with that I
will eventually place into a plugin for later use. As I'm in
development, I keep them there so I can change and keep going along.
Plugins are for finished pieces that you want to use in multiple
projects. If you are developing something that will be used in multiple
projects, get it working first and then create a plugin for it.
Otherwise, if it's just a one-off type of deal, keep it internal..