# Using ActionView helpers elsewhere

**URL:** <https://www.ruby-forum.com/t/using-actionview-helpers-elsewhere/147011>\
**Category:** Rails\
**Created:** [August 27, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/using-actionview-helpers-elsewhere/147011 "2008-08-27T15:48:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Wagaman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Ben\_Wagaman](https://www.ruby-forum.com/u/Ben_Wagaman)\
**Post date:** [August 27, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/using-actionview-helpers-elsewhere/147011/1 "2008-08-27T15:48:31Z")

</div>

I am working on a reporting library (perhaps a gem someday). It’s  
coming along pretty well thus far, though I could use some collective  
intelligence on something.

I would like ActionView::Base (particularly the helpers to be  
available within a lambda. The point of this is to define  
transformations on columns (0…n) within an instance of the class to  
output within an erb template.

For reference, both class A and B below produce the correct result,  
but class C is what I’m trying to do.

class A \< ActionView::Base  
def run  
content\_tag(‘a’,‘b’)  
end  
end

class B \< ActionView::Base  
def run  
l = lambda { content\_tag(‘a’,‘b’) }  
l.call  
end  
end

class C \< ActionView::Base  
attr\_accessor :l

def run  
l.call  
end  
end

a = A.new  
=\> #\<A:0xb35c9a00 @controller=nil, @assigns\_added=nil, @assigns={},  
@view\_paths=[], @logger=nil\>  
a.run  
=\> “b”

b = B.new  
=\> #\<B:0xb35c60f8 @controller=nil, @assigns\_added=nil, @assigns={},  
@view\_paths=[], @logger=nil\>  
b.run  
=\> “b”

c = C.new  
=\> #\<C:0xb35c37b8 @controller=nil, @assigns\_added=nil, @assigns={},  
@view\_paths=[], @logger=nil\>  
c.l = lambda { content\_tag(‘a’,‘b’) }  
=\> #Proc:0xb35bf938@:26(irb)  
c.run  
NoMethodError: undefined method `content_tag' for #<Object:0xb7d249a4> from (irb):26 from (irb):18:in`call’  
from (irb):18:in `run’  
from (irb):27

Any thoughts?
