Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Is there anyone using yaml for storing data
4 Posts
Is there anyone using yaml for storing data

Hi I wanted to know if there is anyone using YAML to store data instead of storing it in database. If anyone is using, please tell me in what kind of situation you opted to use YAML instead of database.

Thanks

basically using YAML instead of database is a situation where you don't need a dynamic data such as I had a task of customizable client interface such as colors of links, visited links, main background, header background color, header text color, etc. Also we have some default colors defined and also need to provide option to client to reset it to website default colors. Doing so storing a static data in database makes not much sense (it works though but not a good option where you have already 50+ models and need to handle such a situation more than once), so I made a YAML file have default colors. Hopes this help you.

Thanks. That really helps.

Yes, it's especially good for simple configuration associated with the web application. Here is a great Rails screencast for creating and using a YAML config file: http://railscasts.com/episodes/85-yaml-configuration-file

In addition, if you need to store configuration-like data with your database records, you can use the useful Rails method serialize: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002229

4 Posts
Login to add your message