Minus your mysterious ‘change the xml’ that worked for me.If you could
produce a more precise example (or at least elaborate on “Doesn’t
work” (raises an exception, does nothing, has the wrong attributes,
something else…)
you might get a more helpful response.
Let’s see…
u = User.find(3)
=> #<User id: 3, company_id: 3, login: “tm_user”, email:
“[email protected]”, crypted_password:
“b695db100847aa269fb477443a289d875cf2e001”, salt:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, timezone: “UTC”,
remember_token: nil, remember_token_expires_at: nil, activation_code:
“bab0c2bc67d43b6871005559b114b9b62b7b70bb”, activated_at: “2008-11-19
22:12:07”, password_reset_code: nil, enabled: true, created_at:
“2008-11-19 22:12:07”, updated_at: “2008-11-19 22:12:07”,
lock_version: 4, address_id: nil>
u.to_xml
=> “<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n
<activated-at type=“datetime”>2008-11-19T22:12:07Z\n
bab0c2bc67d43b6871005559b114b9b62b7b70bb\n
<address-id type=“integer” nil=“true”>\n
<company-id type=“integer”>3\n
b695db100847aa269fb477443a289d875cf2e001\n
[email protected]\n <enabled
type=“boolean”>true\n <id type=“integer”>3\n
<lock-version type=“integer”>4\n
tm_user\n <password-reset-code
nil=“true”>\n <remember-token
nil=“true”>\n <remember-token-expires-at
type=“datetime” nil=“true”>\n
1e3a4ba1ccb233c2bbd92c3bdbb917307523671b\n
UTC\n\n”
Change the XML. Change the timezone from UTC to ABC
a = “<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n
<activated-at type=“datetime”>2008-11-19T22:12:07Z\n
bab0c2bc67d43b6871005559b114b9b62b7b70bb\n
<address-id type=“integer” nil=“true”>\n
<company-id type=“integer”>3\n
b695db100847aa269fb477443a289d875cf2e001\n
[email protected]\n <enabled
type=“boolean”>true\n <id type=“integer”>3\n
<lock-version type=“integer”>4\n
tm_user\n <password-reset-code
nil=“true”>\n <remember-token
nil=“true”>\n <remember-token-expires-at
type=“datetime” nil=“true”>\n
1e3a4ba1ccb233c2bbd92c3bdbb917307523671b\n
ABC\n\n”
Apply it back to the record.
u.from_xml(a)
u.from_xml(a)
=> #<User id: 3, company_id: 3, login: “tm_user”, email:
“[email protected]”, crypted_password:
“b695db100847aa269fb477443a289d875cf2e001”, salt:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, timezone: “UTC”,
remember_token: nil, remember_token_expires_at: nil, activation_code:
“bab0c2bc67d43b6871005559b114b9b62b7b70bb”, activated_at: “2008-11-19
22:12:07”, password_reset_code: nil, enabled: true, created_at:
“2008-11-19 22:12:07”, updated_at: “2008-11-19 22:12:07”,
lock_version: 4, address_id: nil>
Mmmmm. timezone is still UTC.
Let’s save it.
u.save
=> true
u
=> #<User id: 3, company_id: 3, login: “tm_user”, email:
“[email protected]”, crypted_password:
“b695db100847aa269fb477443a289d875cf2e001”, salt:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, timezone: “UTC”,
remember_token: nil, remember_token_expires_at: nil, activation_code:
“bab0c2bc67d43b6871005559b114b9b62b7b70bb”, activated_at: “2008-11-19
22:12:07”, password_reset_code: nil, enabled: true, created_at:
“2008-11-19 22:12:07”, updated_at: “2008-11-19 22:12:07”,
lock_version: 5, address_id: nil>
Looks like the time zone never got changed.
Let’s try with json
u.to_json
=> “{“user”: {“salt”:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, “activated_at”:
“2008-11-19T22:12:07Z”, “remember_token_expires_at”: null,
“crypted_password”: “b695db100847aa269fb477443a289d875cf2e001”,
“password_reset_code”: null, “lock_version”: 5,
“activation_code”: “bab0c2bc67d43b6871005559b114b9b62b7b70bb”,
“timezone”: “UTC”, “id”: 3, “enabled”: true, “address_id”:
null, “remember_token”: null, “company_id”: 3, “login”:
“tm_user”, “email”: “[email protected]”}}”
j = “{“user”: {“salt”: “1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, “activated_at”: “2008-11-19T22:12:07Z”, “remember_token_expires_at”: null, “crypted_password”: “b695db100847aa269fb477443a289d875cf2e001”, “password_reset_code”: null, “lock_version”: 5, “activation_code”: “bab0c2bc67d43b6871005559b114b9b62b7b70bb”, “timezone”: “ABC”, “id”: 3, “enabled”: true, “address_id”: null, “remember_token”: null, “company_id”: 3, “login”: “tm_user”, “email”: “[email protected]”}}”
=> “{“user”: {“salt”:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, “activated_at”:
“2008-11-19T22:12:07Z”, “remember_token_expires_at”: null,
“crypted_password”: “b695db100847aa269fb477443a289d875cf2e001”,
“password_reset_code”: null, “lock_version”: 5,
“activation_code”: “bab0c2bc67d43b6871005559b114b9b62b7b70bb”,
“timezone”: “ABC”, “id”: 3, “enabled”: true, “address_id”:
null, “remember_token”: null, “company_id”: 3, “login”:
“tm_user”, “email”: “[email protected]”}}”
j
=> “{“user”: {“salt”:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, “activated_at”:
“2008-11-19T22:12:07Z”, “remember_token_expires_at”: null,
“crypted_password”: “b695db100847aa269fb477443a289d875cf2e001”,
“password_reset_code”: null, “lock_version”: 5,
“activation_code”: “bab0c2bc67d43b6871005559b114b9b62b7b70bb”,
“timezone”: “ABC”, “id”: 3, “enabled”: true, “address_id”:
null, “remember_token”: null, “company_id”: 3, “login”:
“tm_user”, “email”: “[email protected]”}}”
u.from_json(j)
=> #<User id: 3, company_id: 3, login: “tm_user”, email:
“[email protected]”, crypted_password:
“b695db100847aa269fb477443a289d875cf2e001”, salt:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, timezone: “UTC”,
remember_token: nil, remember_token_expires_at: nil, activation_code:
“bab0c2bc67d43b6871005559b114b9b62b7b70bb”, activated_at: “2008-11-19
22:12:07”, password_reset_code: nil, enabled: true, created_at:
“2008-11-19 22:12:07”, updated_at: “2008-11-19 22:12:07”,
lock_version: 5, address_id: nil>
u.save
=> true
u
=> #<User id: 3, company_id: 3, login: “tm_user”, email:
“[email protected]”, crypted_password:
“b695db100847aa269fb477443a289d875cf2e001”, salt:
“1e3a4ba1ccb233c2bbd92c3bdbb917307523671b”, timezone: “UTC”,
remember_token: nil, remember_token_expires_at: nil, activation_code:
“bab0c2bc67d43b6871005559b114b9b62b7b70bb”, activated_at: “2008-11-19
22:12:07”, password_reset_code: nil, enabled: true, created_at:
“2008-11-19 22:12:07”, updated_at: “2008-11-19 22:12:07”,
lock_version: 6, address_id: nil>
Exact same story.