简体   繁体   中英

How to store user generated content in Rails app

I want to create an website where users can create their own teaching resources, eg blocks of text with embedded images etc.

How should I store this in a database in rails? I've heard mongoDB is good for storing documents but I was planning on using postgresql for the user database etc. and have read that generally you shouldn't mix different types of db

I'm sure this is an obvious question but I couldn't find an answer anywhere...

Thanks,

Graham

There are several things you could do.

1. Use PostgreSQL for both the Users table and the TeachingResources table. You could simply use a content column of type text to save all the data.


2. Use PostgreSQL but use the HStore functionality to basically store a hash of objects of your choosing, this gives you more flexibility. Rails 4 will support this by default , but there is also a gem you can use.


3. Use a combination of PostgreSQL and MongoDB (or any other NoSQL solution) in your app. I don't see this as a bad solution, but it does put you outside of the "new user constraints" in Rails, so this might not be the best route to start with


4. Go NoSQL all the way . There is no reason you shouldn't be able to use MongoDB for your User model. However, you are right that this type of datastorage can not give full ACID guarantees, so be careful with product planning and know it's vulnerabilities (but also its strengths).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM