# Helper methods from controller

**URL:** <https://www.ruby-forum.com/t/helper-methods-from-controller/150178>\
**Category:** Rails\
**Created:** [October 5, 2008, 1:08pm UTC](https://www.ruby-forum.com/t/helper-methods-from-controller/150178 "2008-10-05T13:08:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [October 5, 2008, 1:08pm UTC](https://www.ruby-forum.com/t/helper-methods-from-controller/150178/1 "2008-10-05T13:08:43Z")

</div>

Hi,

I’m not sure i’m my design is correct, but i have around\_filter in the  
controller, where i want to add a small javascript at the end of the  
page. Is there someway i can use the javascript\_tag from the controller?  
i though there where a helpers proxy available.

/Jon

---

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [October 5, 2008, 2:17pm UTC](https://www.ruby-forum.com/t/helper-methods-from-controller/150178/2 "2008-10-05T14:17:31Z")

</div>

Jon S. wrote:

> Hi,
> 
> I’m not sure i’m my design is correct, but i have around\_filter in the  
> controller, where i want to add a small javascript at the end of the  
> page. Is there someway i can use the javascript\_tag from the controller?  
> i though there where a helpers proxy available.

Maybe Im not understanding your situation, but filters are more used for  
application logic and typical cases like logging, benchmarking etc.  
Wouldnt it be better to use the layouts folder and stick the javascript  
in there ?

---

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [October 5, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/helper-methods-from-controller/150178/3 "2008-10-05T14:38:04Z")

</div>

Raja Venkataraman wrote:

> Jon S. wrote:
> 
> > Hi,
> > 
> > I’m not sure i’m my design is correct, but i have around\_filter in the  
> > controller, where i want to add a small javascript at the end of the  
> > page. Is there someway i can use the javascript\_tag from the controller?  
> > i though there where a helpers proxy available.
> 
> Maybe Im not understanding your situation, but filters are more used for  
> application logic and typical cases like logging, benchmarking etc.  
> Wouldnt it be better to use the layouts folder and stick the javascript  
> in there ?

This will be a plugin that enable auto-refresh with ajax, and the  
after\_filter is starting the javascript-update-check-script for the  
configured actions.

---

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [October 6, 2008, 8:09am UTC](https://www.ruby-forum.com/t/helper-methods-from-controller/150178/4 "2008-10-06T08:09:48Z")

</div>

Robby R. wrote:

> On Sun, Oct 5, 2008 at 5:38 AM, Jon S.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > Maybe Im not understanding your situation, but filters are more used for  
> > > application logic and typical cases like logging, benchmarking etc.  
> > > Wouldnt it be better to use the layouts folder and stick the javascript  
> > > in there ?
> > 
> > This will be a plugin that enable auto-refresh with ajax, and the  
> > after\_filter is starting the javascript-update-check-script for the  
> > configured actions.
> 
> This isn’t really how you’d use the before/after filters. What it  
> sounds like is that you need to be able to trigger js to be called on  
> specific actions? You might consider adding the js code to your  
> application layout view… and use a before filter on the specific  
> actions you want this to run and have that show the corresponding js.
> 
> For example:
> 
> before\_filter :trigger\_js\_stuff
> 
> def trigger\_js\_stuff  
> @reload\_page = true  
> end
> 
> In your view…
> 
> \<% if @reload\_page %\>  
> // trigger your js code here  
> \<% end %\>
> 
> Good luck!
> 
> Robby

Thanks Robby, i just put it on github, please have a look and see if  
it’s correct usage,  
[GitHub - jnstq/content\_refresher: Update the client side page every time the model is updated on the server.](http://github.com/jnstq/content_refresher/tree/master). I would like to  
just javascript\_tag @ line 60 on  
[http://github.com/jnstq/content\_refresher/tree/master/lib/equipe/content\_refresher.rb](http://github.com/jnstq/content_refresher/tree/master/lib/equipe/content_refresher.rb)

Jon

---

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [October 6, 2008, 2:51am UTC](https://www.ruby-forum.com/t/helper-methods-from-controller/150178/5 "2008-10-06T02:51:02Z")

</div>

On Sun, Oct 5, 2008 at 5:38 AM, Jon S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Maybe Im not understanding your situation, but filters are more used for  
> > application logic and typical cases like logging, benchmarking etc.  
> > Wouldnt it be better to use the layouts folder and stick the javascript  
> > in there ?
> 
> This will be a plugin that enable auto-refresh with ajax, and the  
> after\_filter is starting the javascript-update-check-script for the  
> configured actions.

This isn’t really how you’d use the before/after filters. What it  
sounds like is that you need to be able to trigger js to be called on  
specific actions? You might consider adding the js code to your  
application layout view… and use a before filter on the specific  
actions you want this to run and have that show the corresponding js.

For example:

before\_filter :trigger\_js\_stuff

def trigger\_js\_stuff  
@reload\_page = true  
end

In your view…

\<% if @reload\_page %\>  
// trigger your js code here  
\<% end %\>

Good luck!

Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
