Create web site in 15 minutes
You will learn "How to create a web site in 15 minutes" with DRG CMS. In the following steps we will create new Ruby on Rails project, update necessary configuration files, create superadmin account and generate simple web site with top menu, main html data part and footer part.
It is assumed that you have Ruby on Rails and MongoDB installed.
Create new rails project.
DRG CMS is just a gem file added to your Rails project. Lets start by creating new Rails project. Go to your projects directory and type in following command where project_name is your project name.
With MongoDB you don't need active_record support therefor if you don't plan to connect to other databases you may also skip active record support.
You have just created new Rails project. DRG CMS can also coexist with your existing project. So instructions below apply to new or existing Rails projects.
Update Rails configuration files
First change to project_name directory.
Prepare some configuration files in order to be able to run DRG CMS.
./Gemfile
Replace or update content of Gemfile with this contents:
source 'https://rubygems.org'
ENV['RAILS_ENV'] ||='development'
gem 'rails'
gem 'activeresource'
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'uglifier'
gem 'non-stupid-digest-assets'
gem 'bcrypt'
gem 'mongoid'
gem 'mongo_session_store-rails5'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'font-awesome-rails'
gem 'kaminari-mongoid'
gem 'kaminari-actionview'
gem 'drg_cms'
gem 'drg_default_html_editor'
if ENV['RAILS_ENV'] == 'development' or ENV['RAILS_ENV'] == 'test'
gem 'puma'
# gem 'my_own_gem', path: '/path_to/my_own_gem'
else
# gem 'my_own_gem'
end
group :development do
gem 'web-console'
gem 'listen'
end
group :test do
gem 'capybara'
gem 'selenium-webdriver'
end
rails,activeresource,sprockets-rails and uglifier are present in all Rails projects.
non-stupid-digest-assets. There has been a lot nice (and less nice) written on Net about assets in Rails 4. This gem avoids some troubles that came with it. If you know how to avoid them, you can leave this gem out.
bcrypt is needed for hashing user's passwords.
mongoid and mongo_session_store-rails5 are required for Ruby on Rails to work with MongoDB. mongo_session_store-rails4 is used for saving sessions to MongoDB.
jquery-rails,jquery-ui-rails are needed for javascript and jquery environments to work.
kaminari is library for paging support. It works fine with mongoid.
font-awesome-rails icons library used by DRG CMS.
drg_cms is main DRG CMS gem. This is all code needed for DRG CMS to work.
drg_default_html_editor provides rich html editor functionality for DRG CMS with inclusion of CKEditor javascript library. Included is also elFinder file manager which integrates excelent with CKEditor. drg_default_html_editor is provided as separate gem because there are lots of javascript editors which can be used for editing data. This gem is prepared as an example how to integrate any html or javascript data entry element into DRG CMS forms and thus extend DRG forms functionality.
This initial Gemfile is sufficient for DRG CMS to work. You will add your gems as the project grows.
After Gemfile has been updated it is time to run bundle install. It usually takes few minutes for bundler to install gems for the first time.
I like to put my gems into vendor directory. Default location is .bundle directory.
config/mongoid.yml
Configuration file for MongoDB and Mongoid gem is similar to database.yml. This configuration file can have lots of options found here. Below are the most common needed options for DRG CMS to work.
clients:
default:
database: my_project_development
hosts:
- localhost:27017
options:
username: user
password: pass
options:
raise_not_found_error: false # this is required
And similar for test and production environments.
Create file config/initializers/session_store.rb
This is important since default cookie store has problems with storing BSON objects and it quickly becomes too small for CMS editors. Replace content of file with this.
expire_after: 1.month
}
Expiration time is of course your decision.
Update config/initializers/assets.rb
DRG CMS uses different set of assets for edit and application mode. This will instruct assets compiler to precompile cms.css and cms.js files which are used in CMS edit mode.
Update config/routes.rb
There are three lines, that need to be added to routes.rb file for DRG CMS.
get '*path' => 'dc_main#page' # must be last statement before end
As you can see main routes point to dc_main page action which handles the logic required for displaying web pages. Since the last statement is very generic it must be the last statement in routes.rb file. Your application specific routes must be specified before it.
Update config/application.rb
Add line to the end of file.
DRG CMS forms will usually be located in app/forms directory. List of directories where DRG CMS will search for forms must be initialized with this command.
Assets files
DRG CMS is using two separate assets configuration files for javascript and css. This is because often large javascript files, which are used for editing data in CMS mode, are not required for presenting data. Therefor DRG CMS uses application.js and application.css for assets in normal mode and cms.js with cms.css for defining assets in edit mode. Which set will be used is defined by session[:edit_mode] and is automatically controlled by DRG CMS.
Setting below are all that is required to run web site.You may overwrite content of files or add lines below to your existing code.
Update app/assets/javascripts/application.js
//= require drg_default_html_editor_application
Create app/assets/javascripts/cms.js
//= require drg_default_html_editor_cms
// This option will also enable slovenian language in elfinder file manager. Default is english.
//= require elfinder/js/i18n/elfinder.sl
Update app/assets/stylesheets/application.css
*= require drg_cms_application
*/
Create app/assets/stylesheets/cms.css
*= require drg_cms_cms
*/
You are almost ready to start web site. In the next chapter you will learn what must be done at the beginning.