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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Pål Bergström wrote:> def crypt_data > self.name = Crypto.encrypt(self.name,key) > end > > def decrypt_data > self.name = Crypto.decrypt(self.name,key) > endAre you sure you don''t mean @name? This is Ruby, not Python, so self would generally refer to the class or module, not the object. -Dave -- Specialization is for insects. -RAH | Have Pun, Will Babble! -me Programming Blog: http://codosaur.us | Work: http://davearonson.com Leadership Blog: http://dare2xl.com | Play: http://davearonson.net * * * * * WATCH THIS SPACE * * * * * | Ruby: http://mars.groupsite.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Dave Aronson wrote:> P�l Bergstr�m wrote: > >> def crypt_data >> � � �self.name = Crypto.encrypt(self.name,key) >> end >> >> def decrypt_data >> � � �self.name = Crypto.decrypt(self.name,key) >> end > > Are you sure you don''t mean @name? This is Ruby, not Python, so self > would generally refer to the class or module, not the object.That''s not true. In an instance method, self refers to the object.> > -DaveBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Pål Bergström wrote:> I pass a value from controller to model with attr_accessor. before_save > works fine but not after_find. What could be wrong?Note this sentence from the documentation: "Unlike all the other callbacks, after_find and after_initialize will only be run if an explicit implementation is defined (def after_find)." Try that. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Tue, Sep 14, 2010 at 09:44, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> That''s not true. In an instance method, self refers to the object.Oops, you''re right, on further research it seems to be a slippery little bugger. No wonder I usually see people using @ (or @@) instead.... -Dave -- Specialization is for insects. -RAH | Have Pun, Will Babble! -me Programming Blog: http://codosaur.us | Work: http://davearonson.com Leadership Blog: http://dare2xl.com | Play: http://davearonson.net * * * * * WATCH THIS SPACE * * * * * | Ruby: http://mars.groupsite.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Dave Aronson wrote:> On Tue, Sep 14, 2010 at 09:44, Marnen Laibow-Koser > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> That''s not true. �In an instance method, self refers to the object. > > Oops, you''re right, on further research it seems to be a slippery > little bugger.Not slippery at all. It''s very well defined.> No wonder I usually see people using @ (or @@) > instead....That has a completely different meaning.> > -DaveBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.