Access to session from plugins

Hi!
I am writing an acts_as_ plugin and i need to access session data
from it. But i cant find any information if this is possible? And if
it is, how.

Cheers!

Mathias

Am 23.02.2006 um 17:17 schrieb Mathias
Stjernström:

Hi!
I am writing an acts_as_ plugin and i need to access session data
from it. But i cant find any information if this is possible? And
if it is, how.

Create a Singleton class and set the session into it in your
ApplicationController’s before_filter.

For example:

class SessionFoomatic
def self.session=(value)
@@session = value
end

def self.session
@@session
end
end

class ApplicationController < ActionController::Base

before_filter :session_foo

protected

def session_foo
SessionFoomatic.session = session
end
end

*m_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Ah, works like a charm, thanks!

Another quite annoying thing is that i have to reload my webserver
after every modification that i make in my plugin, are there any way
of have it auto-reloaded?

Thanks again for the example!

Cheers!

Mathias

I think this is necessary because of the way plugins are loaded.
I don’t know if there is a way around it, or if it would be a good idea
if you could.

_Kevin

I have no special injections in my init.rb but maybe i should :wink:

I found that calling require_dependency ‘acts_as_myplugin’ in the
controller reloads the plugin.
Do not know if this breaks anything but its only when developing the
plugin and so far everything seem good :wink:

Cheers!

Mathias

It depends on your particular plugin. Your init.rb file will only be
evaluated once (during the Initializer processing that gets kicked off
when environment.rb is loaded). As i recall, the ‘acts_as_’ plugin
pattern uses some ActiveRecord injection cunning that happens in the
init.rb file, so this might be an issue wrt. reloading.

  • james

On 2/23/06, Mathias Stjernström [email protected] wrote:

Mathias

from it. But i cant find any information if this is possible? And
end
protected
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

  • J *
    ~