मयंक जैन (makuchaku)
2007-Oct-07 04:28 UTC
[Mechanize-users] How to store a Mechanize object in the database?
Hi, I am trying to save a Mechanize object in database (using a Rails Model). But the save operation throws a TypeError Considering that "agent" is an instance of a Rails Model and "user" is defined as a "text" type in the Model. irb(main):039:0> agent.user = WWW::Mechanize.new #<WWW::Mechanize:0xb71295f0 @follow_meta_refresh=false, @key=nil, @user_agent="WWW-Mechanize/0.6.10 (http://rubyforge.org/projects/mechanize/)", @log=nil, @proxy_addr=nil, @keep_alive=true, @user=nil, @pass=nil, @conditional_requests=true, @proxy_port=nil, @pluggable_parser=#<WWW::Mechanize::PluggableParser:0xb712953c @parsers={"text/html"=>WWW::Mechanize::Page}, defaultWWW::Mechanize::File, read_timeoutnil, keep_alive_time300, ca_filenil, watch_for_setnil, proxy_passnil, auth_hash{}, certnil, history[], open_timeoutnil, connection_cache{}, cookie_jar#<WWW::Mechanize::CookieJar:0xb71295b4 @jar={}>, proxy_usernil, digestnil, passwordnil, redirect_oktrue irb(main):040:0> agent.save TypeError: can''t dump anonymous class Class from /usr/lib/ruby/1.8/yaml/rubytypes.rb:6:in `to_yaml'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `node_export'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `add'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `to_yaml'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:17:in `each'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:17:in `to_yaml'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:16:in `map'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:16:in `to_yaml'' from /usr/lib/ruby/1.8/yaml.rb:387:in `call'' from /usr/lib/ruby/1.8/yaml.rb:387:in `emit'' from /usr/lib/ruby/1.8/yaml.rb:387:in `quick_emit'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:15:in `to_yaml'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `node_export'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `add'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `to_yaml'' from /usr/lib/ruby/1.8/yaml/rubytypes.rb:17:in `each'' ... 14 levels... from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2029:in `attributes_with_quotes'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2128:in `quoted_column_names'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1813:in `create_without_callbacks'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:254:in `create_without_timestamps'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/timestamp.rb:39:in `create'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1789:in `create_or_update_without_callbacks'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:242:in `create_or_update'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in `save_without_validation'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in `save_without_transactions'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction'' from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'' from (irb):40 from (null):0irb(main):041:0> Further, I tried creating a simple WWW::Mechanize instance and did a "to_yaml" on the object - saw a similar error. How can I tackle this? Any suggestions would be welcome :) Thanks! Maku -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20071007/756507e3/attachment.html
मयंक जैन (makuchaku)
2007-Oct-08 01:24 UTC
[Mechanize-users] How to store a Mechanize object in the database?
A pseudo solution of sorts... http://www.makuchaku.info/blog/how-to-effectively-serialize-a-wwwmechanize-object :) Maku On 10/7/07, ???? ??? (makuchaku) <maku at makuchaku.info> wrote:> > Hi, > > I am trying to save a Mechanize object in database (using a Rails Model). > But the save operation throws a TypeError > > Considering that "agent" is an instance of a Rails Model and "user" is > defined as a "text" type in the Model. > > irb(main):039:0> agent.user = WWW::Mechanize.new > #<WWW::Mechanize:0xb71295f0 @follow_meta_refresh=false, @key=nil, > @user_agent="WWW-Mechanize/0.6.10 (http://rubyforge.org/projects/mechanize/)<http://rubyforge.org/projects/mechanize/%29>", > @log=nil, @proxy_addr=nil, @keep_alive=true, @user=nil, @pass=nil, > @conditional_requests=true, @proxy_port=nil, > @pluggable_parser=#<WWW::Mechanize::PluggableParser:0xb712953c > @parsers={"text/html"=>WWW::Mechanize::Page}, defaultWWW::Mechanize::File, > read_timeoutnil, keep_alive_time300, ca_filenil, watch_for_setnil, > proxy_passnil, auth_hash{}, certnil, history[], open_timeoutnil, > connection_cache{}, cookie_jar#<WWW::Mechanize::CookieJar:0xb71295b4 > @jar={}>, proxy_usernil, digestnil, passwordnil, redirect_oktrue > > irb(main):040:0> agent.save > TypeError: can''t dump anonymous class Class > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:6:in `to_yaml'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `node_export'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `add'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `to_yaml'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:17:in `each'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:17:in `to_yaml'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:16:in `map'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:16:in `to_yaml'' > from /usr/lib/ruby/1.8/yaml.rb:387:in `call'' > from /usr/lib/ruby/1.8/yaml.rb:387:in `emit'' > from /usr/lib/ruby/1.8/yaml.rb:387:in `quick_emit'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:15:in `to_yaml'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `node_export'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `add'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:18:in `to_yaml'' > from /usr/lib/ruby/1.8/yaml/rubytypes.rb:17:in `each'' > ... 14 levels... > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2029:in > `attributes_with_quotes'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2128:in > `quoted_column_names'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1813:in > `create_without_callbacks'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:254:in > `create_without_timestamps'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/timestamp.rb:39:in > `create'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1789:in > `create_or_update_without_callbacks'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:242:in > `create_or_update'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in > `save_without_validation'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in > `save_without_transactions'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in > `save'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in > `transaction'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in > `transaction'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in > `transaction'' > from /var/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in > `save'' > from (irb):40 > from (null):0irb(main):041:0> > > > Further, I tried creating a simple WWW::Mechanize instance and did a > "to_yaml" on the object - saw a similar error. > > How can I tackle this? Any suggestions would be welcome :) > > Thanks! > Maku >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20071008/204d11cd/attachment.html