简体   繁体   English

存储用户设置的最佳方法

[英]Best way to store user settings

Yes, I saw this post . 是的,我看到了这篇文章 It seems old and I wanted to ask again, especially with the recent release of Rails 5. 它似乎很旧,我想再问一遍,尤其是在最近发布的Rails 5中。

What is the best way to store user settings in Rails? 在Rails中存储用户设置的最佳方法是什么? It seems has_easy is a decent way. 似乎has_easy是一种不错的方法。 Rails-cached-settings also seems like a good way - but I dislike that there are no default values and it is... rather ambiguous. Rails缓存设置似乎也是一个好方法-但我不喜欢没有默认值,而且它是……很模糊。

Both of these options seem good, but how do they impact performance? 这两个选项似乎都不错,但是它们如何影响性能? If I only have three settings, is it better to have them directly on the model? 如果我只有三个设置,将它们直接放在模型上会更好吗? What if I have ten? 如果我有十个怎么办?

Edit: has_easy is 8 years old, probably not the best option by now. 编辑:has_easy是8岁,现在可能不是最好的选择。

I like starting out simple before making things too complex. 我喜欢从简单开始,然后再使事情变得过于复杂。 If you only have three settings per user, it might not be a bad idea to start with them on the model. 如果每个用户只有三个设置,那么在模型上开始进行设置可能不是一个坏主意。 When it starts to get too complicated, then make the decision to switch to something more extensible. 当开始变得太复杂时,请决定切换到更可扩展的功能。 You will have a lot more information at that point to pick the right way to handle settings. 届时您将获得更多信息,以选择正确的方式来处理设置。

I prefer https://github.com/ledermann/rails-settings for storing model specific settings with optional default values. 我更喜欢https://github.com/ledermann/rails-settings用于存储具有可选默认值的特定于模型的设置。 This stores the settings in a simple has_many association. 这会将设置存储在一个简单的has_many关联中。 The data is stored in a Proc. 数据存储在Proc中。 I assume that a simple join will not have a big impact on performance. 我认为简单的连接不会对性能产生很大的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM