5

I'm creating a website CMS in Rails (for fun and learning) and I'm trying to figure out how I'm going to store the data for an "about" page. Due to the nature of this page, the data will only have one instance, it may change and will be persistent so I want to store it in my database but I'm not sure if this is the best approach.

While a database is obviously quite capable but I feel like it's not the best place for it, as this data is not an object that will ever have multiple instances such as something like a user account.

Is there a normal way of doing this, is storing it in the database the normal thing to do and instead just pull forward a single row form the database?

2 Answers 2

2

I'd store it there, since you have a database anyway and each release can just update the row as needed. I don't see why it matters how many instances you'll have of the class which uses the data. I sometimes create a system table that holds configuration data for the application even though there will only ever be one row. If your app needs a database connection to do anything useful, there's no reason to not put this sort of thing there. You may find you have other similar pages, and so you may restructure your table at some point for their data as well.

1
  • I had a feeling this was going to be the answer someone came back with. I'll use this structure and see how it evolves over time, I was just wondering if anyone had any other interesting way of going about it. Thanks @Andy Sep 6, 2015 at 18:30
1

There are number of ways doing it,

  1. Sometimes even if you see it as a single record, actually it could be multiple records. For example if you want to keep the history of the entries about records could be a list of records with one marked as active

  2. If you have some text in about page and you want to store it in the database, it's possible that you have more text in other pages you need to store in the database (probably page_name,key,value)

  3. you could store it in a key value table, and it won't get more simpler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.