Rails - 关于如何在数据库中存储一组随机参数的建议
好吧,Rails 专家们,我需要一些明智的建议。
我正在尝试使用 SendGrid 的解析 api: http://sendgrid.com/documentation/ApiParse
这里的挑战是 SendGrid 在 API 规范中执行以下操作:
- attachments - 附件数量 包含在电子邮件中。
- Attachment1、attachment2、...、attachmentN - 这些是文件上传名称,其中 N 是附件总数。例如,如果附件数量为0,则不会有附件文件。如果附件数量为3,则参数attachment1、attachment2、attachment3会有文件上传。 TNEF 文件 (winmail.dat) 将被提取并发布所有附件。
我需要将响应存储在数据库中,以便我可以将其发送到延迟作业来完成所有繁重的工作。
存储此信息以便延迟的作业可以使用响应的最佳方式是什么?我可以以某种方式将响应转换为 Mail.new() 对象吗?或者其他一些想法? X 个随机附件使得在不向数据库添加 100 个字段的情况下优雅地解决问题变得很棘手。
谢谢
Ok Rails gurus, I need some smart advice here.
I'm trying to use SendGrid's parse api: http://sendgrid.com/documentation/ApiParse
The big challenge here is that SendGrid does the following in the API spec:
- attachments - Number of attachments
included in email. - attachment1, attachment2, ..., attachmentN - These are file upload names, where N is the total number of attachments. For example, if the number of attachments is 0, there will be no attachment files. If the number of attachments is 3, parameters attachment1, attachment2, and attachment3 will have file uploads. TNEF files (winmail.dat) will be extracted and have any attachments posted.
I need to store the response in the DB so I can send it off to delayed job to do all the heavy lifting.
What's the best way to store this so delayed job can use the response? Can I somehow turn the response into a Mail.new() object? Or some other ideas? The random X of attachments makes it tricky to solve elegantly without add 100 fields to the database.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试序列化附件并存储在单个字段中。我认为重新创建 Mail 对象不会给您带来多大好处。
去这里:
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
并查找标题“在文本列中保存数组、哈希和其他不可映射对象”
I would try serializing the attachments and storing in a single field. I don't think recreating a Mail object will do you much good.
Go here:
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
and look for this title "Saving arrays, hashes, and other non-mappable objects in text columns"
如果我理解正确,我建议如下:
如果您不需要查询字段,则可以将属性哈希作为 YAML 或 JSON 存储到数据库表中的一个字段中。
If I understood right I suggest following:
If you do not need query upon the fields, you chould store the attributes hash as YAML or JSON into one field in database table.