Forum: Ruby on Rails Access to session from plugins

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mathias Stjernström (Guest)
on 2006-02-23 18:18
(Received via mailing list)
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
Manuel H. (Guest)
on 2006-02-23 19:09
(Received via mailing list)
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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Mathias Stjernström (Guest)
on 2006-02-23 22:54
(Received via mailing list)
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
Kevin O. (Guest)
on 2006-02-23 23:25
(Received via mailing list)
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
James A. (Guest)
on 2006-02-25 04:54
(Received via mailing list)
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 <removed_email_address@domain.invalid> 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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
* J *
  ~
Mathias Stjernström (Guest)
on 2006-02-25 14:30
(Received via mailing list)
I have no special injections in my init.rb but maybe i should ;)

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 ;)

Cheers!

Mathias
This topic is locked and can not be replied to.