Forum: Ruby on Rails unmarshal everything as string

Df7ce8d92f80a933a90e2e100d69c45e?d=identicon&s=25 Atip Asvanund (drjoke)
on 2011-11-05 09:26
This problem prevents me from using Rails.cache to store objects other
than string. This used to work fine with Ruby 1.8 and Rails 2.3.
However, with my new setup migrating to Ruby 1.9.2 or 1.9.3 and Rails
3.1.1 I now get this problem.

Please also note that Rails.cache is using memcache in the backend. atip$ /opt/ruby-1.9.2/bin/rails console
Loading development environment (Rails 3.1.1)

irb(main):001:0> user = User.find 1
User Load (0.5ms) SELECT users.* FROM users WHERE = 1 LIMIT 1
=> # User id: 1, nickname: "จอมยุทธ์", username: "jomyoot", created_at:
nil, updated_at: "2011-09-30 13:23:29", active_at: "2011-09-30
13:23:29", homepage_views: 175458, score: 5842, level: 8, stars: 6,
remaining_story_votes: 8, remaining_story_comment_votes: 16,
remaining_stars: 1, latest_tweeter_content: "asdde"

irb(main):002:0> Rails.cache.write "test", user
=> true

irb(main):003:0> test = "test"
=> "\x04\bo:

irb(main):004:0> test.class
=> String
Df7ce8d92f80a933a90e2e100d69c45e?d=identicon&s=25 Atip Asvanund (drjoke)
on 2011-11-05 12:21
I would like to add a further notice that the problem seems to occur
only with Rails ActiveRecord model. I have no problem unmarshalling a
Date class.

irb(main):005:0> d =
=> Mon, 01 Jan -4712
irb(main):006:0> Rails.cache.write "date", d
=> true
irb(main):007:0> x = "date"
=> Mon, 01 Jan -4712
irb(main):008:0> x.class
=> Date
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.