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.
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
Thank you so much. This updated plugin was long awaited!
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
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?
Is it possible to add a moderator to the forums?
I can see an option to Monitor a topic. Is it related to moderating?
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?
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!
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
I have some problems with ovveriding controller methods, could you post any simple example please?
@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.
Great plugin, just what we needed!
We need to a forum that is search engine optimized for our website in order to maximize traffic. Is Savage Beast SEO friendly?
Yes.
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?
@Paresh Mathur
Also I am using the acts_as_authenticated system
@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.
And where is the license of this plugin?
@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.
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…
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.
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?!
Out of curiosity, would you be able to implement this forum multiple times within one application. For instance, if we wanted to have a forum for Northern California, Southern California, and Central California, all with their own individual discussion categories (General, Travel, Dining, etc.), is that a possibility? Or would that involve changing the database tables?
Or is there an easier way to do this where we would have categories for each location (S. Cal, N. Cal, E. Cal), and then subcategories for the discussion categories?
Hi is that plugin is ready for Rails 3.0.1 ?
Can please anybody tell me how i can in the running Savage Beast create a new Post?
I can’t figure it out.
Hey all.
For anybody who’s still looking at this – so far, looks like the only game in the rails-forum-as-plugin town – you should know that it’s main application.js makes one reference right at the end to the old lowpro.js package for prototype, so that should either be downloaded and included aswell, or if you are already using jQuery in your app as well, just rewrite it in that. Also: I didn’t realize this, but the plugins referred to above are included in the app. Later versions will not work correctly, and I don’t suggest they are tried.
*I don’t suggest anybody to try it.
Greetings,
What is the latest version of Rails that SB is known to be compatible with, and is there any likelihood of it being brought forward to Rails 3?
Regards,
-Jeff
Hi Jeff,
It’s Rails 2.3 compatible. I actually do plan to bring it up to Rails 3, but I’m not sure exactly when. Hopefully in the next couple weeks, now that we are fully migrated and have already migrated our own version of SB at Bonanza. Certainly more requests will make me get around to updating it more quickly 🙂
Also open to pull requests if anyone wants to take a stab at it themselves on Github. For our update, I just pulled out Gibberish since it was too much of a PIA. And the Engines functionality is already built into Rails 3, which is convenient.
Bill
Hey Jeff, this is great, thanks!
I would also love to see a Rails 3 version.
Hi,
The forum plugin is working really well. Thank you much. Quick questions, I don’t have deep understanding of rails, but I was wondering if there is a way to have my post controller in my app not interfere with the post controller in the beast directory. Is there a way to redefine the routes?
Thank you,
hi,
What I did was renamed my original post routes and methods in the posts controller. Next I moved the contents of savage beasts post controller into the original post controller and the same for the post models. all seems well. is there something I should watch out for?