Hi everybody !
I''m trying to extend the class ApplicationController with a plugin to
add filters to follow some executions. I don''t know why, but I observed
a weird behaviour and I don''t know why. Here is my code.
init.rb
========require ''myplugin''
myplugin.rb
===========ApplicationController.class_eval do
before_filter do
puts "I''m in the before_filter"
end
end
The things is this filter happens just the first time (the first action
after Webrick is loaded). Well, I tried to do the same thing, extending
ActionController::Base, and it works without problems. But I''d like to
extend ApplicationController and not the Base.
Any ideas ?
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Mar-04 17:13 UTC
Re: Plugin : adding filters in ApplicationController
On Mar 4, 10:30 am, onion wushu <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi everybody ! > > I''m trying to extend the class ApplicationController with a plugin to > add filters to follow some executions. I don''t know why, but I observed > a weird behaviour and I don''t know why. Here is my code. > > init.rb > ========> require ''myplugin'' > > myplugin.rb > ===========> ApplicationController.class_eval do > before_filter do > puts "I''m in the before_filter" > end > end > > The things is this filter happens just the first time (the first action > after Webrick is loaded). Well, I tried to do the same thing, extending > ActionController::Base, and it works without problems. But I''d like to > extend ApplicationController and not the Base. >In development mode your code gets reloaded between requests - the reloaded application controller class doesn''t have this filter added to it. One way of working around this is for your plugin to add a method to base (eg add_my_filter) and call that from whichever controllers use it. There is also a hook ( config.to_prepare ) that it called before each request in development mode Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.