Rails:存储用户设置的最佳实践? [英] Rails: Best practice to store user settings?

查看:78
本文介绍了Rails:存储用户设置的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道存储用户设置的最佳方法是什么?对于Web 2.0应用程序,我希望用户能够选择某些设置.目前只有接收电子邮件通知的时间.

I'm wondering what the best way is to store user settings? For a web 2.0 app I want users to be able to select certain settings. At the moment is it only when to receive email notifications.

最简单的方法是只创建一个设置"模型,并为每个设置创建一列,然后与用户建立1-1关系.

The easiest way would be to just create a Model "Settings" and have a column for every setting and then have a 1-1 relationship with users.

但是有没有更好的解决方案?将信息存储在用户表本身中也许更好?还是我应该使用一个带有"settings_name"和"settings_value"的表来完全打开那里存储的设置类型(在添加选项时不必运行任何迁移)?

But is there a pattern to solve this better? Is it maybe better to store the info in the user table itself? Or should I use a table with "settings_name" and "settings_value" to be completely open about the type of settings stored there (without having to run any migrations when adding options)?

您对此有何看法?

谢谢

推荐答案

我们使用了名为 HasEasy .它将数据存储在垂直表中,但允许您添加验证,存储之前/之后的处理,类型等.

We use the helpful plugin called HasEasy. It stores the data in a vertical table, but allows you to add validations, pre/post storage processing, types, etc.

这篇关于Rails:存储用户设置的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆