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
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 On Feb 23, 2006, at 6:08 PM, Manuel Holtgrewe wrote:> > 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 > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
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 On Thursday, February 23, 2006, at 9:54 PM, Mathias Stjernström wrote:>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 > > > > >On Feb 23, 2006, at 6:08 PM, Manuel Holtgrewe wrote: > >> >> Am 23.02.2006 um 17:17 schrieb Mathias Stjernstr?>> >>> 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 >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your time!
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 <mathias@globalinn.se> wrote:> 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 > > > > > On Feb 23, 2006, at 6:08 PM, Manuel Holtgrewe wrote: > > > > > 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 > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- * J * ~
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 On Feb 25, 2006, at 3:51 AM, James Adam wrote:> 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