开发者

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. 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 qu开发者_运维问答erying and loading), I must create one of those... but how to write an XML/YAML file to store common application parameters? And how to read that file located, for example', in the 'RAILS_ROOT/models' folder using Ruby on Rails?


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.

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:

You have a detailed answer on how to keep settings in an YAML file right here on SO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜