Ruby on Rails - 存储应用程序配置 [英] Ruby on Rails - Storing application configuration

查看:130
本文介绍了Ruby on Rails - 存储应用程序配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相对简单的Rails应用程序,我想存储管理员用户可以在应用程序运行时更改的各种配置设置,例如,允许评论帖子或更改日期的显示格式。

I have a relatively simple Rails app and I would like to store various configuration settings that administrator users can change whilst the application is running, for example, allowing comments on posts or changing the display format of the date.

我知道我可以在environment.rb文件中存储常量等,但这些似乎仅在服务器重新启动时加载。

I know I can store constants etc in the environment.rb file, however these appear to be loaded only when the server is restarted.

有没有其他地方我可以定义这个信息,或者最好保存在数据库中?

Is there an alternative place I can define this information or would it be better to keep it in the database?

任何建议。

感谢。

推荐答案

创建一个单独的表设置,存储您需要的键/值参数。这个解决方案的缺点是性能命中(每次你需要一个设置时查询DB)。要解决这个问题,你可以读/写通过缓存,如cache_money或创建自己的使用Rails.cache

You can use database. Create a separate table "settings" that stores key/value parameters you need. The downside of this solution is a performance hit (querying DB every time you need a setting). To fix this issue you could you read/write through cache like "cache_money" or create your own by using "Rails.cache"

这篇关于Ruby on Rails - 存储应用程序配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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