Greg Willits
2013-Nov-22 05:15 UTC
ApplicationController class method not being called each page load
Ruby 2, Rails 4, bundler I''m trying to package a bunch of my own reusable libs into gems. I did this quite some time ago for Ruby 1.8, Rails 3. Now I''m updating everything, and trying a new approach to the gem structure as well. Something is hinky, and I''ve run out of ideas to figure it out. At this point I have a fresh Rails 4 project, and working on my first gem--it''s a logger which I have used for eons. In ApplicationController I have: class ApplicationController < ActionController::Base global_logger :chatty end The problem I am seeing is that global_logger is being run only one time. In all my previous versions (as a Rails 2 plugin, and a Rails 3 gem) that class method runs from scratch every page load and I count on that behavior to do some things. In this new Rails 4 setup, it is running the first time and that''s it. The rest of my logger code (writing messages from subsequent controllers) seems to work fine. Is there some new thing to Ruby 2 / Rails 4 I''ve not read about? Anyway, before I spew 4 pages of code details, my first question is whether or not the running-once behavior is something new which is expected (doesn''t make sense to me but who knows). If not, then I can provide some details of how I''ve structure the gem, and the class methdods. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6c4e6661d23afea94ec3b564d04137c0%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Nov-22 07:48 UTC
Re: ApplicationController class method not being called each page load
On 22 November 2013 05:15, Greg Willits <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Ruby 2, Rails 4, bundler > > I''m trying to package a bunch of my own reusable libs into gems. I did > this quite some time ago for Ruby 1.8, Rails 3. Now I''m updating > everything, and trying a new approach to the gem structure as well. > Something is hinky, and I''ve run out of ideas to figure it out. > > At this point I have a fresh Rails 4 project, and working on my > first gem--it''s a logger which I have used for eons. > > In ApplicationController I have: > > class ApplicationController < ActionController::Base > global_logger :chatty > end > > The problem I am seeing is that global_logger is being run only one > time. In all my previous versions (as a Rails 2 plugin, and a Rails 3 > gem) that class method runs from scratch every page load and I count on > that behavior to do some things. In this new Rails 4 setup, it is > running the first time and that''s it. The rest of my logger code > (writing messages from subsequent controllers) seems to work fine.I am sure you are mistaken. That code will only be interpreted when the class is loaded (which, by default, in development mode will be at every action, but in production will only be when the server is started). That is true in Rails 3 and Rails 4. Try putting a puts statement above your global_logger line in your rails 3 app and you will see that this is correct. Of course it is entirely possible that the effects of calling global_logger may have changed, that depends on what is in that method. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs5RfUQDVYjZ_QKiPkDFpxcRCzS-Q6AxRP8C6R7%2BnWnSw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Nov-22 10:27 UTC
Re: ApplicationController class method not being called each page load
On Friday, November 22, 2013 7:48:18 AM UTC, Colin Law wrote:> > On 22 November 2013 05:15, Greg Willits <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org<javascript:>> > wrote: > > > > The problem I am seeing is that global_logger is being run only one > > time. In all my previous versions (as a Rails 2 plugin, and a Rails 3 > > gem) that class method runs from scratch every page load and I count on > > that behavior to do some things. In this new Rails 4 setup, it is > > running the first time and that''s it. The rest of my logger code > > (writing messages from subsequent controllers) seems to work fine. > > I am sure you are mistaken. That code will only be interpreted when > the class is loaded (which, by default, in development mode will be at > every action, but in production will only be when the server is > started). That is true in Rails 3 and Rails 4. Try putting a puts > statement above your global_logger line in your rails 3 app and you > will see that this is correct. Of course it is entirely possible that > the effects of calling global_logger may have changed, that depends on > what is in that method. > >The development mode code reloader is much smarter as of rails 3.2 - it no longer reloads everything on every request. It will only reload a file if it thinks it needs to (although it almost certainly errs on the side of caution). If you want something to run on every request, use a before/after/around filter Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/27be1b32-b370-4b7f-961f-33a310dbd505%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Nov-22 10:38 UTC
Re: ApplicationController class method not being called each page load
On 22 November 2013 10:27, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Friday, November 22, 2013 7:48:18 AM UTC, Colin Law wrote: >> >> On 22 November 2013 05:15, Greg Willits <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > >> > The problem I am seeing is that global_logger is being run only one >> > time. In all my previous versions (as a Rails 2 plugin, and a Rails 3 >> > gem) that class method runs from scratch every page load and I count on >> > that behavior to do some things. In this new Rails 4 setup, it is >> > running the first time and that''s it. The rest of my logger code >> > (writing messages from subsequent controllers) seems to work fine. >> >> I am sure you are mistaken. That code will only be interpreted when >> the class is loaded (which, by default, in development mode will be at >> every action, but in production will only be when the server is >> started). That is true in Rails 3 and Rails 4. Try putting a puts >> statement above your global_logger line in your rails 3 app and you >> will see that this is correct. Of course it is entirely possible that >> the effects of calling global_logger may have changed, that depends on >> what is in that method. >> > > The development mode code reloader is much smarter as of rails 3.2 - it no > longer reloads everything on every request. It will only reload a file if > it thinks it needs to (although it almost certainly errs on the side of > caution). If you want something to run on every request, use a > before/after/around filterThanks for that clarification Fred, that explains why the OP is seeing a change in development mode. I presume the situation in production has not changed, so in that case in rails 3 global_logger would only have been run on server start and that is still the case. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuxxzHXgvjz94xPxZo7v7ox06RPuRnMsQPVFT2MescZnA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Greg Willits
2013-Nov-22 16:27 UTC
Re: ApplicationController class method not being called each page load
I did forget to clarify I only care about :development, and definitely not mistaken about what I''m seeing. However, now that Fred mentions 3.2 specifically, that''s relevant. While I''m running some small sites on 3.2, I mostly used this global_logger code in the dev of some big sites on 2.0 through 3.1 -- been doing non-ruby thing s since about when 3.2 came out, so haven''t really relied on it during new development like I am now with 4. OK, I''ll give the before filter angle a whirl. Thanks (as always) Fred. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/76140f9de73b6417786141f7ad00f145%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.