Question: I hope the problem is clear. Is there an alternative way not to get undefined reference error without implementing template functions in header files? Thanks in advance.

Answer: 
Your solution might be too confusing later and you may have more headaches later.

I advice this: (1) Use a NoSQL such as MongoDB. (2) Migrate all your data from previous DB. (3) Then put your DB under versioning with. You can, since it's document-based and not SQL.

Mongo has an excellent Gem too, called MongoID <https://github.com/mongoid/mongoid> 

This way you can use a CMS which has much bigger community (like Refinery). Further more: your DB backups solved easily becuase you are able to roll back anytime with Git or simply clone your DB sometimes, also you can automatize backups, etc.

HTH
For what reason do you want to keep your content into a git repository? What exactly is the problem that makes you hate databases so much? A DBMS is built for fast data reads and writes, whereas git is built for change management. This is an architectural choice with which you might shoot yourself in the foot.

If the problem lies in users that overwrite entries, then you should rather introduce functionality to archive previous versions (or the diff's of them) not overwrite them. For example the rails\_admin gem does that

And even with immediate committing you will not escape the problem that one user opens an entry for editing and keeps it for an hour until he saves it, where at the same time another user does a quick edit in 5 minutes. Here you need to send from the client which revision has he been editing and in the case of conflict, show an interface where the user can compare his revisions with the ones made by the other user. Or if you're advanced then you can do it the google-docs way. enable simultaneous editing.