Forum: Ruby on Rails How to hook ActionController when plugin init in development mode?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C59cae5d861c9f84f6ead08e445745a0?d=identicon&s=25 冷血儿 (Guest)
on 2009-05-27 04:11
(Received via mailing list)
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
A23a35087d9dba5f1332e5db2fb1b5d2?d=identicon&s=25 Neo (Guest)
on 2009-05-27 06:31
(Received via mailing list)
试试ActionController::Base.send :inlcude,AcPlugin

2009/5/27 冷血儿 <cncolder@gmail.com>

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


--
明天会更好
C59cae5d861c9f84f6ead08e445745a0?d=identicon&s=25 冷血儿 (Guest)
on 2009-05-27 08:04
(Received via mailing list)
I tried that way. It doesn't work even first request.


2009/5/27 Neo <neocanable@gmail.com>
Acd62030df551952268e84c8fff26a5b?d=identicon&s=25 James Adam (lazyatom)
on 2009-05-31 19:07
(Received via mailing list)
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-darke...

 - James
This topic is locked and can not be replied to.