March 30th 2020
In these modern times, it is almost impossible to find a web-site which does not have some sort of Blog/Post functionality. For the simplicity and ease of content creation, Content Management Systems (CMS) have been become very popular. CMS in general is an application designed to create, manage or publish content.
Ruby on Rails is an open source web application framework which can be used to create a CMS. To avoid creating and writing a bunch of code over and over we have created a simple engine that behaves as Content Management System called CMS9.
CMS9 is a library for Rails apps that automatically generates a CMS dashboard. CMS9 dashboard gives non-technical users a clean interface that allows them to create, edit, search, and delete definitions, field types and posts related to it. CMS9 provides complete CRUD functionality.
In this way it is easy to create the structure of some Blog, Post or any other form, to add, remove or change fields via user interface and the best thing is that you can use it easily in your app.
To add CMS9 engine to your app you need to add gem in Gemfile:
Re-bundle, then run the installer:
$ rails generate cms9:install [DEF_ROUTE]
Install generator will mount CMS9 route, add current_user configurator initializer and additional configuration for Ckeditor.
Restart your server, and visit http://localhost:3000/cms9 (or where you have defined CMS9 to be mounted) to see your new CMS9 dashboard in action.
On the dashboard, you can create a Post Type, where you define the fields which this form will contain, as text, text area, number, select, multiple select, image, date, time, date_time.
Once when you have created the form for a specific post type (example Blog), you can populate this form.
To display populated values in your app, follow these steps:
1. Generate controller Posts
$ rails g controller Posts
2. Add routes in routes file:
3. In the Posts controller create a method for the index page.
@posts = Cms9::Post.all.limit(20).order('created_at desc')
post_definition = Cms9::PostDefinition.where(name: params[:name]).first
@posts = post_definition.posts
In your view for the index page you can access the values of each field , just by changing the name of the field I.E.:
You can make any kind of layout for your posts and show them however you want. Once you made a simple layout, you are ready to create as many posts as you want. It's that easy.