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.

  14. Paresh Mathur
    March 17th, 2010 at 23:52 | #14

    I implemented all the things that is mentioned in the above tutorial, but still when I try to go to forums/new it redirects me to login page.

    I know my admin? is working as when I created some posts (after disabling the :login_required in forums controller) I get Administrator written next to the name. New posts also have this. What can be the problem?

  15. Paresh Mathur
    March 18th, 2010 at 00:01 | #15

    @Paresh Mathur
    Also I am using the acts_as_authenticated system

  16. Ian
    April 14th, 2010 at 02:49 | #16

    @billybobby
    I fixed this by creating the class request_error.rb in config/initializers with the code below:

    class ActionController::Request
    def relative_url_root
    @@relative_url_root ||= case
    when @env["RAILS_RELATIVE_URL_ROOT"]
    @env["RAILS_RELATIVE_URL_ROOT"]
    when server_software == ‘apache’
    @env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, ”)
    else

    end
    end
    end

    Found the clue at this site:

    http://railsforum.com/viewtopic.php?pid=73991#p73991

    Still not 100% sure why it breaks but this seems to fix it.

  17. forumer
    May 25th, 2010 at 03:43 | #17

    And where is the license of this plugin?

  18. May 26th, 2010 at 16:25 | #18

    @forumer: um, in the plugin directory? Informally speaking, its license is the “I don’t care if or how you use it, just don’t sue me.”-license.

  19. freefallr
    May 31st, 2010 at 03:16 | #19

    Can savage beast be used as a standalone forum? I don’t currently have a user model in my website and would prefer if savage beast could cope with that by creating it’s own usermodel and login/out facility…

  20. May 31st, 2010 at 12:23 | #20

    If it’s a standalone forum you’re after, I would investigate “Beast.” That is the codebase from which Savage Beast originally came from. The reason I wrote SB was because for my site (and many others) the site owner specifically wants the forum experience to be tied in with the rest of the site experience. But if you do’nt, then Beast should be ideally suited for you. That is its ideal use case.

  21. freefallr
    June 1st, 2010 at 14:53 | #21

    Interesting stuff. Seems like savage-beast is better supported and documented though. Once I’ve added restful-authentication, I should be able to use savage beast - right?!

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