# How to hook ActionController when plugin init in development mode?

**URL:** <https://www.ruby-forum.com/t/how-to-hook-actioncontroller-when-plugin-init-in-development-mode/168890>\
**Category:** Rails\
**Created:** [May 27, 2009, 4:11am UTC](https://www.ruby-forum.com/t/how-to-hook-actioncontroller-when-plugin-init-in-development-mode/168890 "2009-05-27T04:11:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 27, 2009, 4:11am UTC](https://www.ruby-forum.com/t/how-to-hook-actioncontroller-when-plugin-init-in-development-mode/168890/1 "2009-05-27T04:11:42Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 27, 2009, 6:31am UTC](https://www.ruby-forum.com/t/how-to-hook-actioncontroller-when-plugin-init-in-development-mode/168890/2 "2009-05-27T06:31:29Z")

</div>

è¯•è¯•ActionController::Base.send :inlcude,AcPlugin

2009/5/27 å†·è¡€å„¿ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> def index
> 
> Thanks
> 
> colder
> 
> >

–  
æ˜Žå¤©ä¼šæ›´å¥½

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 27, 2009, 8:04am UTC](https://www.ruby-forum.com/t/how-to-hook-actioncontroller-when-plugin-init-in-development-mode/168890/3 "2009-05-27T08:04:00Z")

</div>

I tried that way. It doesn’t work even first request.

2009/5/27 Neo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 31, 2009, 7:07pm UTC](https://www.ruby-forum.com/t/how-to-hook-actioncontroller-when-plugin-init-in-development-mode/168890/4 "2009-05-31T19:07:34Z")

</div>

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:

> **[The Even Darker Art Of Rails Engines Presentation](https://www.slideshare.net/railsconf/the-even-darker-art-of-rails-engines-presentation)**
>
> The Even-Darker Art of Rails Engines @lazyatom github.com/lazyatom/engines Rails 2.3 history November 2005 itâ€™s distracting! ...

- James
