Savage Beast 2.0 has been the de facto solution for those looking to add a message forum to their existing Rails site, but it was created more than a year ago, and had many aspects that tied it to Rails 2.0. Also, it relied on the Engines plugin, which is not the most lightweight plugin. Although Engines doesn’t seem to affect performance, it did rub some people the wrong way.
After a year’s worth of promises that an update was “coming soon,” an update has finally arrived and is now available at Github.
Detailed instructions on getting it rolling with Rails 2.3 follow.
Installation
Currently, the following is necessary to use the Savage Beast plugin:
- The Savage Beast 2.3 plugin. Go to your application’s root directory and:
script/plugin install git://github.com/wbharding/savage-beast.git
- Most of the stuff you need to run Beast…
- Redcloth:
gem install Redcloth.
Make sure you add “config.gem 'RedCloth'
” inside your environment.rb, so that it gets included. - A bunch of plugins (white_list, white_list_formatted_content, acts_as_list, gibberish, will_paginate). If you’re using Rails 2.2 or earlier, you’ll need the Engines plugin, if you’re on Rails 2.3, you don’t need Engines. The easiest way to install these en masse is just to copy the contents of savage_beast/tested_plugins to your standard Rails plugin directory (/vendor/plugins). If you already have versions of these plugins, you can just choose not to overwrite those versions
- Redcloth:
- Go to your application’s root directory and run “
rake savage_beast:bootstrap_db
” to create the database tables used by Savage Beast. If it happens you already have tables in your project with the names Savage Beast wants to use, your tables won’t be overwritten (though obviously SB won’t work without its tables). To see the tables Savage Beast uses, look in lib/tasks/savage_beast.rake in your Savage Beast plugin folder. - Next run “
rake savage_beast:bootstrap_assets
” to copy Savage Beast stylesheets and images to savage_beast asset subdirectories within your public directory. - Implement in your User model the four methods in plugins/savage_beast/lib/savage_beast/user_init that are marked as
"#implement in your user model
“ - Add the line “
include SavageBeast::UserInit
” to your User model. Location shouldn’t matter unless you intend to override it. - Add the line “
include SavageBeast::ApplicationHelper
” to ApplicationHelper within your application_helper.rb file. - Implement versions of the methods in SavageBeast::AuthenticationSystem (located in /plugins/savage_beast/lib) in your application controller if they aren’t already there (note: technically, I believe only “login_required” and “current_user” are necessary, the others give you more functionality). Helpful commenter Adam says that if you have the “helper :all” line in your application controller, be sure to add the “SavageBeast::AuthenticationSystem” line after that.
If you’re using Rails 2.0-2.2, and thus using the Engines plugin, you’ll need a couple extra steps:
- Add this line to the top of your environment.rb, right after the require of boot:
require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
- Move the routes.rb file from the “savage-beast/config” directory to the root (“savage-beast”) directory of the plugin. Then add the line “
map.from_plugin :savage_beast
” to your routes.rb. Location shouldn’t matter unless you intend to override it.
And off you go! When you visit your_site/forums something should happen. I’ve been creating new forums by visiting /forums/new. There’s probably a hidden admin view somewhere.
Implementing Your Own Views and Controllers
Just create a new file in your /controllers or /views directories with the same name as the file you want to override in Savage Beast. If you just want to override a particular method in a controller, you can do that piecemeal if you just leave your XController empty except for the method you wanted to override (Note: I know this piecemeal method adding works with the Engines plugin installed, but haven’t tested it without).
If you’re integrating this into an existing site, I’d recommend you start by creating a forums layout page (/app/views/layouts/forums.html.erb). This will give you a taste of how easy it is to selectively override files from the plugin.
Demo
You can check out a (slightly-but-not-too-modified) version of Savage Beast online at Bonanzle. The differences between our version and the version checked into Subversion are 1) addition of topic tagging (users can tag topics to get them removed, etc) 2) recent post list shows posts in unique topics, rather than showing posts from the same topic repeatedly (there’s another blog on here about the SQL I used to do that) and 3) skinning. None of those changes feel intrinsic to what SB is “supposed to do,” which is why they aren’t checked in.
Conclusion
Comments are most welcome. I’ll be checking in changes to the project as I find bugs and improvements in using it, but this is admittedly something I don’t have a lot of spare time to closely follow (see my other entries on the wonders of entrepreneurship). Hopefully others can contribute patches as they find time. If you like the plugin, feel free to stop by Agile Development and give it a rating so that others can find it in the future.