I''m trying to move some of my application''s code into a plugin, specifically the part that deals with web analytics. Some of the features allow the controller to fire events that get displayed in the views as JS code through a partial or helper. I''m currently doing this with instance variables, but when I move it to a class or instance variable of my plugin class, it persists between requests. I guess this makes sense because the plugin is loaded on startup. What I have working is making it an instance variable of ApplicationController: class MyPlugin ApplicationController.instance_variable_set("@my_plugin_event", nil) end which is cleared on every request. It works, but I feel like I''m working against the grain here and doing something wrong. Is what I''m doing OK, or is there a better way? To make it clear, I want to be able to do something like "notice_event(''blah'')" in the controller of the main application, and have the plugin''s helper know about "blah" for the current request, but not the next request. Thanks Sean -- 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.
Anthony Crumley
2010-Apr-12 22:07 UTC
Re: Clearing a plugins instance variables on each request
Sean, Would flash.now work? http://apidock.com/rails/ActionController/Flash/FlashHash/now Anthony Crumley http://commonthread.com On Sun, Apr 11, 2010 at 11:11 PM, SeanWalberg <swalberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m trying to move some of my application''s code into a plugin, > specifically the part that deals with web analytics. Some of the > features allow the controller to fire events that get displayed in the > views as JS code through a partial or helper. I''m currently doing this > with instance variables, but when I move it to a class or instance > variable of my plugin class, it persists between requests. I guess > this makes sense because the plugin is loaded on startup. > > What I have working is making it an instance variable of > ApplicationController: > > class MyPlugin > ApplicationController.instance_variable_set("@my_plugin_event", > nil) > end > > which is cleared on every request. It works, but I feel like I''m > working against the grain here and doing something wrong. > > Is what I''m doing OK, or is there a better way? To make it clear, I > want to be able to do something like "notice_event(''blah'')" in the > controller of the main application, and have the plugin''s helper know > about "blah" for the current request, but not the next request. > > Thanks > > Sean > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
SeanWalberg
2010-Apr-13 02:21 UTC
Re: Clearing a plugins instance variables on each request
It would seem to do what I''m looking for, though was the flash meant for objects? Either way, I''ll look at the implementation to see if I can use similar methods. Thanks, Sean On Apr 12, 5:07 pm, Anthony Crumley <anthony.crum...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sean, > > Would flash.now work? > > http://apidock.com/rails/ActionController/Flash/FlashHash/now > > Anthony Crumleyhttp://commonthread.com > > > > On Sun, Apr 11, 2010 at 11:11 PM, SeanWalberg <swalb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''m trying to move some of my application''s code into a plugin, > > specifically the part that deals with web analytics. Some of the > > features allow the controller to fire events that get displayed in the > > views as JS code through a partial or helper. I''m currently doing this > > with instance variables, but when I move it to a class or instance > > variable of my plugin class, it persists between requests. I guess > > this makes sense because the plugin is loaded on startup. > > > What I have working is making it an instance variable of > > ApplicationController: > > > class MyPlugin > > ApplicationController.instance_variable_set("@my_plugin_event", > > nil) > > end > > > which is cleared on every request. It works, but I feel like I''m > > working against the grain here and doing something wrong. > > > Is what I''m doing OK, or is there a better way? To make it clear, I > > want to be able to do something like "notice_event(''blah'')" in the > > controller of the main application, and have the plugin''s helper know > > about "blah" for the current request, but not the next request. > > > Thanks > > > Sean > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.
Anthony Crumley
2010-Apr-13 02:47 UTC
Re: Re: Clearing a plugins instance variables on each request
Sean, I think flash.now would be fine for objects because it is only there during the request and is not persisted. Anthony Crumley http://commonthread.com On Mon, Apr 12, 2010 at 9:21 PM, SeanWalberg <swalberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It would seem to do what I''m looking for, though was the flash meant > for objects? Either way, I''ll look at the implementation to see if I > can use similar methods. > > Thanks, > > Sean > > On Apr 12, 5:07 pm, Anthony Crumley <anthony.crum...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Sean, > > > > Would flash.now work? > > > > http://apidock.com/rails/ActionController/Flash/FlashHash/now > > > > Anthony Crumleyhttp://commonthread.com > > > > > > > > On Sun, Apr 11, 2010 at 11:11 PM, SeanWalberg <swalb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > I''m trying to move some of my application''s code into a plugin, > > > specifically the part that deals with web analytics. Some of the > > > features allow the controller to fire events that get displayed in the > > > views as JS code through a partial or helper. I''m currently doing this > > > with instance variables, but when I move it to a class or instance > > > variable of my plugin class, it persists between requests. I guess > > > this makes sense because the plugin is loaded on startup. > > > > > What I have working is making it an instance variable of > > > ApplicationController: > > > > > class MyPlugin > > > ApplicationController.instance_variable_set("@my_plugin_event", > > > nil) > > > end > > > > > which is cleared on every request. It works, but I feel like I''m > > > working against the grain here and doing something wrong. > > > > > Is what I''m doing OK, or is there a better way? To make it clear, I > > > want to be able to do something like "notice_event(''blah'')" in the > > > controller of the main application, and have the plugin''s helper know > > > about "blah" for the current request, but not the next request. > > > > > Thanks > > > > > Sean > > > > > -- > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.