2

我有一个 ruby​​ on rails 4 应用程序,我正在使用omniauth-facebookgem 进行身份验证。我有

@omniauth = request.env["omniauth.auth"]

现在我想将用户的教育历史 ( @omniauth[:extra][:raw_info][:education])保存在数据库education的表列中。是一个包含对象(即返回)的 Array 对象。Auth@omniauth[:extra][:raw_info][:education]OmniAuth::AuthHash@omniauth[:extra][:raw_info][:education][0].classOmniAuth::AuthHash

Rails api 说“Active Record 可以使用 YAML 序列化文本列中的任何对象。为此,您必须通过调用类方法 serialize 来指定它。这使得存储数组、哈希和其他不可映射的对象成为可能无需做任何额外的工作。” 所以我做了以下事情,它似乎正在工作:

auth.education = @omniauth[:extra][:raw_info][:education]
auth.save

这有什么缺点吗?有没有更好的方法(比如使用json等)?我能想到的一个缺点是,以这种方式保存数据会使我可能不需要的搜索和查询变得困难。

非常感谢。

4

0 回答 0