With the code you''ve got here, set_channels is a method of the module
Juggernaut (i.e. invokable through Juggernaut.set_channels), and
therefore won''t be added to any classes which include the Juggernaut
module as instance methods. Is that what you wanted?
Basically, with your current code, the value of ''self'' at the
point of
execution for ''Juggernaut.set_channels'' is the module
Juggernaut,
which doesn''t have any variable or method ''session''.
The ''session''
variable or method I''m guessing that you''re after is the one
available
in ActionController::Base, and all subclasses. David Black''s book
explains this very well, and I can highly recommend it if you want to
understand how classes, modules, objects and methods interact.
Typically in a plugin you might do something like this (this could all
be in init.rb, not that such is good style but it should work):
module Juggernaut
def set_channels(chan) # note - no ''self''
sessions[:juggernaut_channels] = chan
end
end
ActionController::Base.send(:include, Juggernaut)
At this point, once the plugin is loaded, all of your controllers have
a ''set_channels'' *instance* method available, so you can do:
class MyController < ApplicationController
def some_action
# ... stuff....
set_channels(some_arg)
# ... other stuff....
end
end
HTH
- james
On 7/5/06, Alex MacCaw <maccman@gmail.com> wrote:> I''m trying to access the session in a rails plugin, so as to set
it as
> below.
>
> 1. module Juggernaut
> 2.
> 3. def self.set_channels(chan)
> 4. session[:juggernaut_channels] = chan
> 5. end
> 6. end
> 7.
> 8. module ActionController
> 9. class Base
> 10. include Juggernaut
> 11. end
> 12. end
>
> At the moment I get: undefined local variable or method `session''
for
> Juggernaut:Module
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
* J *
~