Any suggestions on how best to gain access to session-type information while in an ActiveRecord callback, such as after_save? I am encrypting some information in the database, using the generalized encryption/decryption handler in "Agile Web Development With Rails" (p 375ff). I got it working, and now I want to reference a session field (a user PIN) which is NOT stored in the database... for security reasons. I can''t seem to gain access to the session method: 1. attempting to use session[''user''][''pin''] gives me an "undefined variable or method" 2. attempting to use UserController.session[''user''][''pin''] gives me a message saying that it''s expecting an integer, not a string. Any ideas as to how to either (1) gain access to the session hash or (2) provide my own application-wide storage mechanism? Thanks...jon --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jimcfisher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-06 02:23 UTC
Re: Using session-type data in an ActiveRecord callback...
I wouldn''t do it this way since it kind of muddy''s up the controller & model portions of the MVC. Instead you should create an function that will set the PIN in the user model like this. attr_accessor :pin Then in your controller just pass it to a user object user = User.find_by_id(session[:user][:id]) user.pin = session[:user][:pin] user.save! in the Model after_save # do whatever with the pin user.pin # this will call it now that you have set it end That''s the basic gist of it, I haven''t tested any of this could but I hope its clear enough to understand. hope that helps, Jim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jimcfisher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-06 02:25 UTC
Re: Using session-type data in an ActiveRecord callback...
oops I meant instead of this> after_save > # do whatever with the pin > user.pin # this will call it now that you have set it > enddo this after_save self.pin #to call the current user instances pin. end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Very cool, Jim... thank you very much... just the kind of guidance I was looking for. I''ll give it a shot tomorrow. ...jon On May 5, 7:25 pm, jimcfis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> oops I meant instead of this > > > after_save > > # do whatever with the pin > > user.pin # this will call it now that you have set it > > end > > do this > > after_save > self.pin #to call the current user instances pin. > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---