Adding variables through modules

Hi --


I'm trying to enhance a set of controllers which can set the level of
Class MenuControllder < ApplicationController
include BasicTest

module BasicTest # in lib/basic_test.rb
@test = nil
def self.included controller
   @test =

def basic_filter
    raise @test

This doesn't work at all. @test is nil by the time it calls

Actually you've got two totally unrelated @test variables here: the
one belonging to the module object BasicTest, and one in an instance
method which will belong to whatever object calls the method
(basic_filter). Instance variables always belong to "self", which can
be an object of any class.

If I use @@test then @@test results in the last controller that was
built by the server.

I need a new instance of BasicTest for each controller, and I need it to
not be accessed by other controllers that are inheriting BasicTest.

Modules don't have instances, and they don't get inherited. So I'm
not totally sure what you're aiming for here. But maybe
instance_variable_set would help? I'm thinking of something like

   def self.included(controller)
     controller.before_filter do |c| # c is an instance of controller

though since you can always get from a controller instance to its
class's name easily (, you don't really need to store
this information.

Can you explain a little more what you want to happen?