[英]How to write an XML/YAML file to store application parameters? And how to read that file using Ruby on Rails?
I am using Ruby on Rails 3 and I should decide definitely whether store common parameter for my application in a XML file, in a Yaml file or in the database. 我正在使用Ruby on Rails 3,我应该明确决定是否将应用程序的公共参数存储在XML文件,Yaml文件或数据库中。 Currently, the database is my choice.
目前,数据库是我的选择。
What I should make as parameters is something like these: 我应该做为参数的东西是这样的:
min_name_length
max_name_length
min_surname_length
max_surname_length
...
What is the best choice? 最佳选择是什么?
If the answer is "XML file" or "YAML file" (I think so because these approach saves a lot of database querying and loading), I must create one of those... but how to write an XML/YAML file to store common application parameters? 如果答案是“ XML文件”或“ YAML文件”(我想是因为这些方法节省了很多数据库查询和加载),那么我必须创建其中一种...但是如何编写XML / YAML文件进行存储常用的应用参数? And how to read that file located, for example', in the 'RAILS_ROOT/models' folder using Ruby on Rails?
以及如何使用Ruby on Rails读取位于“ RAILS_ROOT / models”文件夹中的文件(例如)?
You have several different options here, but it's best to choose between file-based or database. 您在这里有几个不同的选项,但是最好在基于文件的数据库或数据库的数据库之间进行选择。
Database-stored settings: 数据库存储的设置:
I personally like the database better and use this rails3 fork of ledderman's rails-settings plugin . 我个人更喜欢数据库,并使用ledderman的rails-settings插件的rails3 分支 。
It's quite simple to setup and flexible enough for my uses. 设置非常简单,并且足够灵活,适合我的使用。 You can specify your settings names, default values and it's quite straightforward.
您可以指定设置名称,默认值,这非常简单。
YAML file-stored settings: YAML文件存储设置:
You have a detailed answer on how to keep settings in an YAML file right here on SO . 您对如何在SO上的YAML文件中保留设置有详细的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.