Reputation: 7314
I'm making a cms and have 10 or so single pages that just contain text but need to be editable, pages like 'About', 'Faq' that rarely change but can be edited in a wysiwyg editor if needed.
I could create a model for each page, i.e an About model with one field 'content' for the text then always call it as About.first
but it seems like a waste for the other pages that will have similar content, is there a DRY-er way of doing this or a gem?
Upvotes: 1
Views: 303
Reputation: 13952
Gems? There's lots of "Rails CMS" gems. Try http://www.refinerycms.com/ or https://github.com/comfy/comfortable-mexican-sofa for two of the more popular ones.
If you want to do it yourself: there's a million ways, but here's one...
Create a "Pages" model. Each "page" can have a 'code' (eg. about, faq, etc), a 'content' field, and possibly others (such as title, seo_description, etc). Users could edit existing pages, but not add new pages - as the developer, you'd add new records to the pages table via migrations or something. You'd also make it so users can't edit the 'code' field of your pages model.
Then, you'd also create a 'pages' controller, and have one method for each page in your pages model. Fetch the page from the Page
model, based on the relevant page code
.
Upvotes: 1