Home > Rails > Savage Beast 2.3, a Rails Message Forum Plugin

Savage Beast 2.3, a Rails Message Forum Plugin

November 5th, 2009

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:

  1. The Savage Beast 2.3 plugin. Go to your application’s root directory and:
    script/plugin install git://github.com/wbharding/savage-beast.git
  2. 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
  3. 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.
  4. Next run “rake savage_beast:bootstrap_assets” to copy Savage Beast stylesheets and images to savage_beast asset subdirectories within your public directory.
  5. 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
  6. Add the line “include SavageBeast::UserInit” to your User model. Location shouldn’t matter unless you intend to override it.
  7. Add the line “include SavageBeast::ApplicationHelper” to ApplicationHelper within your application_helper.rb file.
  8. 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:

  1. 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‘)
  2. 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.

Bill Rails

  1. RC
    November 21st, 2009 at 12:48 | #1

    Hi,

    I tried installing it, but am getting:

    /var/www/…/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:9:
    in `included’: undefined method `has_many’ for Object:Class (NoMethodError)

    any ideas?
    ricardo

  2. Aaron
    November 22nd, 2009 at 06:05 | #2

    Thank you so much. This updated plugin was long awaited!

  3. Aaron
    November 22nd, 2009 at 06:08 | #3

    Also… typo here:

    Redcloth: gem install Redcloth. Make sure you add “config.gem ‘RedCloth’” inside your environment.rb, so that it gets included.

    Redcloth should be RedCloth in the first sentence

  4. Aaron
    November 23rd, 2009 at 11:50 | #4

    Hello, I am getting a problem with the ‘reply_to_topic’ on the topics show page. According to Firebug, ReplyForm is not defined. Any ideas?

  5. Sarwagya
    December 7th, 2009 at 02:08 | #5

    Is it possible to add a moderator to the forums?
    I can see an option to Monitor a topic. Is it related to moderating?

  6. Dow
    December 17th, 2009 at 14:04 | #6

    Hi, I’m installing savage beast into a newly-created application. The database doesn’t have any tables initially.

    My problem is in step 3:
    run “rake savage_beast:bootstrap_db”
    Lines 120 and 121 of savage-beast.rake add columns to the ‘users’ table, which isn’t created by the CreateSavageTables migration. Therefore, it seems that a ‘users’ table needs to exist before SavageBeast can install. Any special requirements on how that table should be structured?

  7. billybobby
    December 28th, 2009 at 10:01 | #7

    Hi,

    I’m using savage beast on rails 2.3.3 and everything works fine except for the RSS feed. I get the following error when I click the rss button:

    undefined method `relative_url_root’ for #

    The error comes from this file on line #11:
    vendor/plugins/savage-beast/app/views/posts/index.rss.builder

    Line #11 is:
    xml.tag! “atom:link”, :rel => ’search’, :type => ‘application/opensearchdescription+xml’, :href => “http://#{request.host_with_port+request.relative_url_root}/open_search.xml”

    Anyone experience similar problems or have a solution/insight into where I might look to fix this? Thanks!

  8. December 29th, 2009 at 01:25 | #8

    Hi..I’m Rails beginer..
    I have a problem when adding line “include SavageBeast::UserInit” in my User model.., That show error : “uninitialized constant SavageBeast::UserInit::Monitorship”. What should I do to solve this problem???

    And then about routing. I try to access http://localhost:3000//forums/ , but there is no route can be found…Do I need to set config/routes.rb?? how to set that??…thanks

  9. Michal
    January 3rd, 2010 at 08:10 | #9

    I have some problems with ovveriding controller methods, could you post any simple example please?

  10. January 6th, 2010 at 23:22 | #10

    @Aaron The ReplyForm bug is due to savage beast’s javascript page not being included. You can find it in /vendor/plugins/savage-beast/public/javascripts/application.js. You can either include it manually or copy the contents into one of your own javascript pages.

    @Dow You need to supply your own user table, though Savage Beast expects a user model similar to that provided by the restful_authentication plugin.

  11. Lux
    January 9th, 2010 at 17:47 | #11

    Great plugin, just what we needed!

  12. Andreas
    February 12th, 2010 at 17:04 | #12

    We need to a forum that is search engine optimized for our website in order to maximize traffic. Is Savage Beast SEO friendly?

  13. February 15th, 2010 at 04:46 | #13

    Yes.

  1. November 5th, 2009 at 18:54 | #1