I''d like to execute some code only during first invocation of controller - sort of a init method. The subsequent invocations do not need to invoke this code. How do I achieve it ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Tue, Apr 22, 2008 at 2:24 PM, Arun <arun.gupta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''d like to execute some code only during first invocation of > controller - sort of a init method. The subsequent invocations do not > need to invoke this code. > > How do I achieve it ?Um, what is it you want to do? Each call to a given controller''s action is in a brand new controller instance, so any initialize method is useless. If it''s one-time initialization of something, then you want config.after_initialize in your environment.rb Jason --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > How do I achieve it ? > > Um, what is it you want to do? Each call to a given controller''s > action is in a brand new controller instance, so any initialize method > is useless.I''m trying to port some Java EE Servlet code to Rails controller/ action and am trying to find out the best place for Servlet.init() method.> > If it''s one-time initialization of something, then you want > config.after_initialize in your environment.rbAh, can you provide some docs/examples of that ? -Arun> > Jason--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Apr 22, 7:49 pm, Arun <arun.gu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > How do I achieve it ? > > > Um, what is it you want to do? Each call to a given controller''s > > action is in a brand new controller instance, so any initialize method > > is useless. > > I''m trying to port some Java EE Servlet code to Rails controller/ > action and am trying to find out the best place for Servlet.init() > method. >in config/initializers? Fred> > > > If it''s one-time initialization of something, then you want > > config.after_initialize in your environment.rb > > Ah, can you provide some docs/examples of that ? > > -Arun > > > > > Jason--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can use the before_filter class method which will execute code before any action is done in your controller. I''m not sure what you mean by "first invocation of a controller" since as Jason pointed out each call to a controller creates a new instance. Can you explain more? (For details on the filters look here http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html) Nicholas On Apr 22, 1:24 pm, Arun <arun.gu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to execute some code only during first invocation of > controller - sort of a init method. The subsequent invocations do not > need to invoke this code. > > How do I achieve it ?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > I''m trying to port some Java EE Servlet code to Rails controller/ > > action and am trying to find out the best place for Servlet.init() > > method. > > in config/initializers?So what do I define in config/initializers and how do I invoke it ? -Arun> > Fred > > > > > > If it''s one-time initialization of something, then you want > > > config.after_initialize in your environment.rb > > > Ah, can you provide some docs/examples of that ? > > > -Arun > > > > Jason--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok figured out that all *.rb files are read in config/initializers so that is working. But greeting = "this is it!" or @greeting = "this is it!" does not allow me to access it in the view. How do I define my "public static final" constants here ? -Arun On Apr 22, 5:53 pm, Arun <arun.gu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m trying to port some Java EE Servlet code to Rails controller/ > > > action and am trying to find out the best place for Servlet.init() > > > method. > > > in config/initializers? > > So what do I define in config/initializers and how do I invoke it ? > > -Arun > > > > > Fred > > > > > If it''s one-time initialization of something, then you want > > > > config.after_initialize in your environment.rb > > > > Ah, can you provide some docs/examples of that ? > > > > -Arun > > > > > Jason--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Quoting Arun <arun.gupta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Ok figured out that all *.rb files are read in config/initializers so > that is working. But > > greeting = "this is it!" > > or > > @greeting = "this is it!" > > does not allow me to access it in the view. > > How do I define my "public static final" constants here ? >Is it a class variable or an instance variable? If the former, just add "GREETING = "this is it!" after the class statement and before any def statements. If the latter, you need to describe more how it is used. HTH, Jeffrey --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---