I'm trying to enhance a set of controllers which can set the level of
Class MenuControllder < ApplicationController
module BasicTest # in lib/basic_test.rb
@test = nil
def self.included controller
@test = controller.name
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
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 (self.class.name), you don't really need to store
Can you explain a little more what you want to happen?