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
Älphä Blüë
2009-Jul-03 19:33 UTC
Re: How to dynamically load plugin files on every request?
Vikrant wrote:> 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. > > -thanksI 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. -- Posted via http://www.ruby-forum.com/.
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? - thanks On Jul 4, 12:33 am, "Älphä Blüë" <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> wrote:> Vikrant wrote: > > 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. > > -- > Posted viahttp://www.ruby-forum.com/.
Simon Macneall
2009-Jul-04 06:31 UTC
Re: How to dynamically load plugin files on 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 Cheers Simon On Sat, 04 Jul 2009 14:24:46 +0800, Vikrant <nasa42-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > - thanks >
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 ActiveSupport::Dependencies.load_once_paths.delete RAILS_ROOT + ''/ vendor/plugins/my_plugin/lib'' but that didn''t work out, so I changed it too - ActiveSupport::Dependencies.explicitly_unloadable_constants << ''MyPlugin'' ActiveSupport::Dependencies.load_once_paths.delete RAILS_ROOT + ''/ vendor/plugins/my_plugin/lib'' - thanks for your answer. On Jul 4, 11:31 am, "Simon Macneall" <macne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > Cheers > Simon > > On Sat, 04 Jul 2009 14:24:46 +0800, Vikrant <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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? > > > - thanks
Simon Macneall
2009-Jul-04 06:56 UTC
Re: How to dynamically load plugin files on every request?
Your welcome. The differences probably mean we are using different versions of Rails. Cheers Simon On Sat, 04 Jul 2009 14:52:28 +0800, Vikrant <nasa42-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > ActiveSupport::Dependencies.load_once_paths.delete RAILS_ROOT + ''/ > vendor/plugins/my_plugin/lib'' > > but that didn''t work out, so I changed it too - > > ActiveSupport::Dependencies.explicitly_unloadable_constants << > ''MyPlugin'' > ActiveSupport::Dependencies.load_once_paths.delete RAILS_ROOT + ''/ > vendor/plugins/my_plugin/lib'' > > - thanks for your answer. > > On Jul 4, 11:31 am, "Simon Macneall" <macne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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 >> >> Cheers >> Simon >> >> On Sat, 04 Jul 2009 14:24:46 +0800, Vikrant <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > 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? >> >> > - thanks >
Hi - Why not develop the plugin in your app''s /lib directory first? Once you''re happy with how it works, you can transfer it over to the plugin''s /lib directory That way you don''t have to restart the server or change your apps configuration options Gavin http://handyrailstips.com/ On Jul 3, 7:04 pm, Vikrant <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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
Älphä Blüë
2009-Jul-04 13:31 UTC
Re: How to dynamically load plugin files on every request?
Gavin Morrice wrote:> Hi - Why not develop the plugin in your app''s /lib directory first? > > Once you''re happy with how it works, you can transfer it over to the > plugin''s /lib directory > > That way you don''t have to restart the server or change your apps > configuration options > > Gavin > > http://handyrailstips.com/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.. -- Posted via http://www.ruby-forum.com/.