How much html do you write in the view, verses generating from a database?

I'm learning Ruby on Rails, and want to learn with the best practices, so:

How much of your content for you pages to your write in the view, verses storing the text in a db table and passing the information in though the controller and model?

My current procedure is write any one-off text in the view, and handle any duplicate items with the db, but I feel like at times this may be overkill, and other times that I am repeating myself too much, and by code is not 'DRY'.

Thanks in advance for your incite/advice, Nick.

2 thoughts on “How much html do you write in the view, verses generating from a database?”

  1. Usually, static text is static html. Seems like your head is in the right place, thinking about best practices and whatnot. You know what might be useful to you? Theres a Chrome extension called Octotree that lets you view github repositories in a folder life format, similar to a text editor. Install it and have a look at others peoples rails applications, specifically the views, and you can see how others do it. The extension will let you easily view this code.

  2. It really depends on the situation. You might want to read up on helpers and presenters. Sometimes static content is best put inside of a partial so you only write it once.

    I store things in the database when it needs to be accessed dynamically, and it’s not a formula. For example, links to outside websites that are in random places all over the website should be in a database table so that you don’t need to manually update the links.


Leave a Comment