2010/7/26 Pål Bergström <li...@ruby-forum.com>: > That I know. I was hoping to do something similar to what I had before, > when I could use cgi. Something easy using before_save and after_find. > > What I want to achieve is to aes encrypt selected columns in the > database using a key stored in the users browser as a cookie. I do it ( > or used to do it) like this. > > In each model I have a before_save and after_find. There I pass the > value from the params, or from the database after find, to a module > where the string was either encrypted or decrypted with the key stored > in a cookie. That cookie was fetched with the help of cgi in the module. > It worked great. But not now, as Rack is taking the place of cgi.
I would just add the functionality to ActiveRecord: Build a module that does the AES stuff: module MyAes def self.append_features( base ) base.before_save do |model| model.encrypted_stuff = encrypt( model.plain_old_data ) if model.respond_to?( :plain_old_data ) end end def self.append_features( base ) base.after_find do |model| model.plain_old_data = decrypt( model.encrypted_stuff ) if model.respond_to?( :plain_old_data ) end end end Mix the module into ActiveRecord, in environment.rb: class ActiveRecord::Base include MyAes end class Foo < ActiveRecord::Base attr_accessor :plain_old_data end -- Greg Donald destiney.com | gregdonald.com -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.