# Scope problem: controller class methods and helpers

**URL:** <https://www.ruby-forum.com/t/scope-problem-controller-class-methods-and-helpers/161805>\
**Category:** Rails\
**Created:** [March 2, 2009, 4:46pm UTC](https://www.ruby-forum.com/t/scope-problem-controller-class-methods-and-helpers/161805 "2009-03-02T16:46:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jbc](https://www.ruby-forum.com/u/jbc)\
**Post date:** [March 2, 2009, 4:46pm UTC](https://www.ruby-forum.com/t/scope-problem-controller-class-methods-and-helpers/161805/1 "2009-03-02T16:46:01Z")

</div>

[http://pastie.org/404716](http://pastie.org/404716)

Only produces “hello”, not “world”.

Which is as designed, but how do I make it do what I want - namely,  
set a variable in a class method, and have that variable available in  
a view helper?

---

<div class="post-metadata">

**Author:** ![jbc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jbc](https://www.ruby-forum.com/u/jbc)\
**Post date:** [March 2, 2009, 4:48pm UTC](https://www.ruby-forum.com/t/scope-problem-controller-class-methods-and-helpers/161805/2 "2009-03-02T16:48:23Z")

</div>

On Mar 2, 3:25 pm, jbc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://pastie.org/404716](http://pastie.org/404716)
> 
> Only produces “hello”, not “world”.
> 
> Which is as designed, but how do I make it do what I want - namely,  
> set a variable in a class method, and have that variable available in  
> a view helper?

Only instance variables of the controller are copied across to the  
view (your bar is an instance variable of the class). easiest way  
would probably be to have an accessor method for it and then you can  
do controller.bar in your view.

Fred
