szimek
2008-Mar-11 23:50 UTC
Where to set a variable so it''s loaded only once and available for all controllers?
Hi, I''m using GeoIP that loads database file with countries when the GeoIP object is created. Where should I initialize this object, so it would be loaded only once (not for every request) and available for all controllers? The code looks like this: geo_ip = GeoIP.new("#{RAILS_ROOT}/public/GeoIP.dat") Thanks in advance --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2008-Mar-11 23:51 UTC
Re: Where to set a variable so it''s loaded only once and available for all controllers?
> I''m using GeoIP that loads database file with countries when the GeoIP > object is created. Where should I initialize this object, so it would > be loaded only once (not for every request) and available for all > controllers? > > The code looks like this: > geo_ip = GeoIP.new("#{RAILS_ROOT}/public/GeoIP.dat")Tail end of environment.rb. Or in one of the new initializer hooks that helps keep it out of environment.rb. You may want to make that GEO_IP to make it more obvious it''s "site wide". --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Feurio
2008-Mar-20 13:10 UTC
Re: Where to set a variable so it''s loaded only once and available for all controllers?
If you put this into environment.rb or one of the new initializer hooks how to prevent this from running for example if you do a rake db:migrate? Chances are that your tables (for your ActiveRecord Objects) are not there and everything blow up... Is there a way to ask rails if we run our environment as a migration? Feurio On 12 Mrz., 00:51, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > I''m using GeoIP that loads database file with countries when the GeoIP > > object is created. Where should I initialize this object, so it would > > be loaded only once (not for every request) and available for all > > controllers? > > > The code looks like this: > > geo_ip = GeoIP.new("#{RAILS_ROOT}/public/GeoIP.dat") > > Tail end of environment.rb. Or in one of the newinitializerhooks that > helps keep it out of environment.rb. > > You may want to make that GEO_IP to make it more obvious it''s "site wide".--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
toby privett
2008-Mar-21 00:56 UTC
Re: Where to set a variable so it''s loaded only once and available for all controllers?
> I''m using GeoIP that loads database file with countries when the GeoIP > object is created. Where should I initialize this object, so it would > be loaded only once (not for every request) and available for all > controllers?You could put in the Application Controller. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---