Forum: Ruby on Rails Can you use a mixin to add action methods to an ActionContro

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
pacred (Guest)
on 2007-05-22 01:00
(Received via mailing list)
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 = ...
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
it in the .rhtml file.  Does anyone know why this is?  Did I just
the code incorrectly or am I using mixins incorrectly

I briefly read that you can only use mixins to define non-action
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
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
feel I am incorrectly using the mixin.


View this message in context:
Sent from the RubyOnRails Users mailing list archive at
This topic is locked and can not be replied to.