冷血儿
2009-May-27 02:10 UTC
How to hook ActionController when plugin init in development mode?
Hi all~ I want to add some methods to ActionController. And I generate a plugin. Although this example looks like strange. init.rb require "ac_plugin" ApplicationController.send(:include, AcPlugin) lib/ac_plugin.rb module AcPlugin def index render :text => "Hello!" end end And then I open http://localhost/user.xml. It works, but only first time. When I refresh that page. I got a error "No action responded to index". I think: Rails maybe reload ActionController everytime under developmemt mode. How can I hook this? Thanks colder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Neo
2009-May-27 04:30 UTC
Re: How to hook ActionController when plugin init in development mode?
试试ActionController::Base.send :inlcude,AcPlugin 2009/5/27 冷血儿 <cncolder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Hi all~ > I want to add some methods to ActionController. And I generate a > plugin. Although this example looks like strange. > > init.rb > require "ac_plugin" > ApplicationController.send(:include, AcPlugin) > > lib/ac_plugin.rb > module AcPlugin > def index > render :text => "Hello!" > end > end > > And then I open http://localhost/user.xml. It works, but only first time. > When I refresh that page. I got a error "No action responded to index". > I think: Rails maybe reload ActionController everytime under developmemt > mode. > > How can I hook this? > > Thanks > > > > colder > > > >-- 明天会更好 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
冷血儿
2009-May-27 06:03 UTC
Re: How to hook ActionController when plugin init in development mode?
I tried that way. It doesn''t work even first request. 2009/5/27 Neo <neocanable-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > 试试ActionController::Base.send :inlcude,AcPlugin > > > > -- > 明天会更好 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Adam
2009-May-31 17:06 UTC
Re: How to hook ActionController when plugin init in development mode?
Use ''config.to_prepare'' in your init.rb to include your module at the start of every request in development mode. See my RailsConf presentation for more details: http://www.slideshare.net/railsconf/the-even-darker-art-of-rails-engines-presentation - James On May 27, 7:03 am, 冷血儿 <cncol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I tried that way. It doesn''t work even first request. > > 2009/5/27 Neo <neocana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > > > 试试ActionController::Base.send :inlcude,AcPlugin > > > -- > > 明天会更好