# Can you use a mixin to add action methods to an ActionContro

**URL:** <https://www.ruby-forum.com/t/can-you-use-a-mixin-to-add-action-methods-to-an-actioncontro/104727>\
**Category:** Rails\
**Created:** [May 21, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/can-you-use-a-mixin-to-add-action-methods-to-an-actioncontro/104727 "2007-05-21T23:00:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pacred](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@pacred](https://www.ruby-forum.com/u/pacred)\
**Post date:** [May 21, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/can-you-use-a-mixin-to-add-action-methods-to-an-actioncontro/104727/1 "2007-05-21T23:00:11Z")

</div>

I am trying to use a module to define a common interface between several  
ActiveRecord model classes, but I am having trouble setting the instance  
variable in the mixin functions. For example, I have a function,  
def showusername  
@user = …  
end  
If I put this function in the action controller, it works fine, but if I  
move it to the module, the instance variable @user is nil when I try to  
call  
it in the .rhtml file. Does anyone know why this is? Did I just  
implement  
the code incorrectly or am I using mixins incorrectly

I briefly read that you can only use mixins to define non-action  
methods.  
Does anyone know if this is true and why that would be the case?

Anyway, I would greatly appreciate any advice. I found examples of  
people  
using mixins to add methods to Active Record classes, but none of these  
functions tried to set instance variables or acted as action methods, so  
I  
feel I am incorrectly using the mixin.

Thanks,  
Chris

–  
View this message in context:  
[http://www.nabble.com/Can-you-use-a-mixin-to-add-action-methods-to-an-ActionController--tf3756642.html#a10617591](http://www.nabble.com/Can-you-use-a-mixin-to-add-action-methods-to-an-ActionController--tf3756642.html#a10617591)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
