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:
-
Added text column “feed” to Comments table in DB
-
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
- 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.
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 K. 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:
-
Added text column “feed” to Comments table in DB
-
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
- 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.