Monday, September 13, 2010

[Rails] Problem with attr_accessor

I pass a value from controller to model with attr_accessor. before_save
works fine but not after_find. What could be wrong?

This is what I use in index
@test = Test.find(:all)
@test.each {|a| a.key = cookies[:thekey]}

and this in create, show, edit:

@test.key = cookies[:thekey]

This is my model:
attr_accessor :key

after_find :decrypt_data
define_method(:after_find) { }
before_save :crypt_data

private

def crypt_data
self.name = Crypto.encrypt(self.name,key)
end

def decrypt_data
self.name = Crypto.decrypt(self.name,key)
end
--
Posted via http://www.ruby-forum.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-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate