This is the 4th incarnation, and 2nd Ruby on Rails version, of the content management system used by Dan and Dave Nawara. This time, however, we’re taking it a little more serious. We’re also pimpin’ it out in Rails 2.x, so get ready for easy CMS goodness.
This is simply the CMS core; to get more functionality, look around for plugins.
Please make your rails app as normal.
$ rails your_app $ cd your_app
Next, install Natto as a plugin.
$ cd vendor/plugins $ git clone git@github.com:djnawara/natto.git
Alternately, you could install Natto (and all of your plugins) as a git submodule.
$ git submodule add git@github.com:djnawara/natto.git vendor/plugins/natto
Natto also requires the following plugins installed:
Engines git://github.com/lazyatom/engines.git acts_as_tree git://github.com/rails/acts_as_tree.git acts_as_state_machine git://github.com/freels/acts_as_state_machine.git attachment_fu git://github.com/technoweenie/attachment_fu.git mimetype-fu git://github.com/mattetti/mimetype-fu.git
The following commands will help you install these plugins as git submodules:
git submodule add git://github.com/lazyatom/engines.git vendor/plugins/engines git submodule add git://github.com/rails/acts_as_tree.git vendor/plugins/acts_as_tree git submodule add git://github.com/freels/acts_as_state_machine.git vendor/plugins/acts_as_state_machine git submodule add git://github.com/technoweenie/attachment_fu.git vendor/plugins/attachment_fu git submodule add git://github.com/mattetti/mimetype-fu.git vendor/plugins/mimetype-fu
Please also install these as gems/plugins:
ruby-openid htmlentities mattetti-googlecharts git://github.com/mattetti/googlecharts.git Ya2YAML git://github.com/ptb/ya2yaml.git haml/sass git://github.com/nex3/haml.git
After installing haml, please make sure and install it into your application:
$ haml --rails /path/to/your/application
Set up the plugin routes, by editing your application’s routes.rb file and adding this line to the very top of the file:
map.from_plugin :natto
This will load the routes from RAILS_ROOT/vendor/plugins/natto/routes.rb. If you end up with routing issues down the road, make sure you don’t have conflicts with this file.
At the bottom of your RAILS_ROOT/config/routes.rb, we need to set the root route to go to the home page defined in the Natto system (we will bootstrap one below). Make sure the bottom of your file looks like this:
# Install the default routes as the lowest priority. map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' # Add the root route here map.root :controller => 'pages', :action => 'home'
Next, add this line just below the rails boot line in your config/environment.rb file:
require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
Go into the Natto plugin directory, and run the install script. This will create a backups folder, remove some of the files which the rails command generates, and copy over configuration files.
$ cd vendor/plugins/natto $ ruby install.rb
The install also generates your site keys, which help to better secure your encrypted passwords. If you would like to use your own site keys settings, please make the changes before you run the bootstrap command. Note the generated site_keys.rb file looks a lot like the ones from the restful_authentication plugin. I basically copied their code for the authentication system (thanks, gang!).
Specifically, install.rb deletes the following (go ahead and just do it manually, if you like):
RAILS_ROOT/public/index.html RAILS_ROOT/public/images/rails.png RAILS_ROOT/app/controllers/application.rb RAILS_ROOT/app/helpers/application_helper.rb
It also copies the following from the plugin directory to your application’s configuration:
PLUGIN_ROOT/config/mail.yml PLUGIN_ROOT/config/sass.yml PLUGIN_ROOT/config/hide_from_js_nav.yml PLUGIN_ROOT/config/initializers/mail.rb PLUGIN_ROOT/config/initializers/sass.rb PLUGIN_ROOT/config/initializers/hide_from_js_nav.rb PLUGIN_ROOT/config/initializers/site_keys.rb
You can now build and populate the system’s database. This will create a default administrative user for you with the following credentials:
Username: admin Password: admin
Please change this password, or make a new administrative user and delete this one, upon your first login.
Please note again that encrypted passwords are dependent on your site keys being properly set up. (Run the install.rb file before you do this!) Your database should not have any pre-existing data when you run this command.
$ script/generate plugin_migration $ rake db:migrate $ rake natto:bootstrap
There is also a command to reset the users table (deleting everyone registered) in order to reset the administrator password. This is obviously dangerous in production, but can be useful while in development.
$ rake natto:bootstrap_admin
You may wish to set some configuration variables in your environment files. The Natto module declares the following variables:
Natto.site_title = "Natto CMS" Natto.host = "localhost:3000" Natto.tango_home = "/plugin_assets/natto/images/tango-icon-theme/" Natto.max_violation_votes = 3
You will most likely end up overriding the first two variables. The host variable should most likely get overridden inside each environments/*.rb file.
The max_violation_votes variable determines how many votes declaring a comment as a violation cause it to be hidden.
If you want to use your own version of a controller or helper, I recommend that you copy the one from the Natto plugin, or better yet, extend it. Also, remember that you can copy views to your main application and then edit those in place.