Steve Koppelman
2006-Dec-05 20:46 UTC
Extending acts_as_commentable with serialize -- stack error
I''m using acts_as_commentable as a plugin, and I have a hash of Structs
I want to store in a text column I added to the Comments table. I did
the following:
1. Added text column "feed" to Comments table in DB
2. Created a file $RAILS_ROOT/lib/commentable_extensions.rb:
module CommentableExtensions
module Juixie
module Acts #:nodoc:
module Commentable #:nodoc:
module ClassMethods
def acts_as_commentable
serialize :feed, Hash
end
end
end
end
end
end
3. Added to environment.rb
require ''commentable_extensions"
Opening a console I can load a Comment via
c = Comment.find(:first)
I can assign my hash to c.feed. But when I attempt c.save, I get this:
>> c.save
SystemStackError: stack level too deep
from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:13:in
`to_yaml_properties''
from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:167:in `to_yaml''
from c:/ruby/lib/ruby/1.8/yaml.rb:387:in `quick_emit''
from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:164:in `to_yaml''
from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:173:in `to_yaml''
from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:172:in `to_yaml''
from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:170:in `to_yaml''
from c:/ruby/lib/ruby/1.8/yaml.rb:387:in `quick_emit''
.... [snip]
Any ideas on what I''m doing wrong?
Thanks.
--
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-/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
-~----------~----~----~----~------~----~------~--~---
Steve Koppelman
2006-Dec-06 02:33 UTC
Re: Extending acts_as_commentable with serialize -- stack er
Followup: After creating a smaller hash of structs and finding that #to_yaml worked fine and then getting the stack overflow error when calling #to_yaml on my app''s larger but no more complex hash (a 7K, 15-member hash of 7-element flat structs), I''m wondering if #to_yaml is a feeble little method that only works with the smallest and simplest of objects. Now I''m off to look for another AR serialization solution. Any suggestions? Steve Koppelman wrote:> I''m using acts_as_commentable as a plugin, and I have a hash of Structs > I want to store in a text column I added to the Comments table. I did > the following: > > 1. Added text column "feed" to Comments table in DB > > 2. Created a file $RAILS_ROOT/lib/commentable_extensions.rb: > > module CommentableExtensions > module Juixie > module Acts #:nodoc: > module Commentable #:nodoc: > module ClassMethods > def acts_as_commentable > serialize :feed, Hash > end > end > end > end > end > end > > 3. Added to environment.rb > > require ''commentable_extensions" > > Opening a console I can load a Comment via > > c = Comment.find(:first) > > I can assign my hash to c.feed. But when I attempt c.save, I get this: > >>> c.save > SystemStackError: stack level too deep > from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:13:in > `to_yaml_properties'' > from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:167:in `to_yaml'' > from c:/ruby/lib/ruby/1.8/yaml.rb:387:in `quick_emit'' > from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:164:in `to_yaml'' > from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:173:in `to_yaml'' > from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:172:in `to_yaml'' > from c:/ruby/lib/ruby/1.8/yaml/rubytypes.rb:170:in `to_yaml'' > from c:/ruby/lib/ruby/1.8/yaml.rb:387:in `quick_emit'' > .... [snip] > > Any ideas on what I''m doing wrong? > > Thanks.-- 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-/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 -~----------~----~----~----~------~----~------~--~---