# Clearing a plugins instance variables on each request

**URL:** <https://www.ruby-forum.com/t/clearing-a-plugins-instance-variables-on-each-request/186717>\
**Category:** Rails\
**Created:** [April 12, 2010, 6:12am UTC](https://www.ruby-forum.com/t/clearing-a-plugins-instance-variables-on-each-request/186717 "2010-04-12T06:12:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SeanWalberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@SeanWalberg](https://www.ruby-forum.com/u/SeanWalberg)\
**Post date:** [April 12, 2010, 6:12am UTC](https://www.ruby-forum.com/t/clearing-a-plugins-instance-variables-on-each-request/186717/1 "2010-04-12T06:12:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SeanWalberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@SeanWalberg](https://www.ruby-forum.com/u/SeanWalberg)\
**Post date:** [April 13, 2010, 12:08am UTC](https://www.ruby-forum.com/t/clearing-a-plugins-instance-variables-on-each-request/186717/2 "2010-04-13T00:08:15Z")

</div>

Sean,

Would flash.now work?

[http://apidock.com/rails/ActionController/Flash/FlashHash/now](http://apidock.com/rails/ActionController/Flash/FlashHash/now)

Anthony C.

> **[Commonthread](https://commonthread.com)**
>
> Instantly connect and build rapport with anyone you meet, in person or online.

---

<div class="post-metadata">

**Author:** ![SeanWalberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@SeanWalberg](https://www.ruby-forum.com/u/SeanWalberg)\
**Post date:** [April 13, 2010, 4:22am UTC](https://www.ruby-forum.com/t/clearing-a-plugins-instance-variables-on-each-request/186717/3 "2010-04-13T04:22:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SeanWalberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@SeanWalberg](https://www.ruby-forum.com/u/SeanWalberg)\
**Post date:** [April 13, 2010, 4:48am UTC](https://www.ruby-forum.com/t/clearing-a-plugins-instance-variables-on-each-request/186717/4 "2010-04-13T04:48:40Z")

</div>

Sean,

I think flash.now would be fine for objects because it is only there  
during  
the request and is not persisted.

Anthony C.

> **[Commonthread](https://commonthread.com)**
>
> Instantly connect and build rapport with anyone you meet, in person or online.
