savage beast

Extracted from The Soup (the-soup.net) is the Savage Beast plugin - a rails engine of the popular Beast forum. Savage Beast simplifies the addition of multiple forums to your rails app, associating 1 or more forum to a AR Model instance. For instance adding a forum to a project model,
1
2
3
4

class Project < ActiveRecord::Base
  has_one :forum, :as => :owner, :dependent => :destroy
end
as you can note above, SB adds a model attribute to polymorphically relate to the forum owner. If you are doing nested routes to forums, topics and posts, overload the appropriate controller and before filter. For instance, if you route /project/1/forum, the forums_controller may look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

class ForumsController < ApplicationController

  #this is the standard before filter called by SB
  def find_or_initialize_forum
    if params[:id] && params[:project_id]
      @project = Project.find(params[:project_id])
      @forum = @project.forum.find(params[:id])
    elsif params[:id]
      @forum = Forum.find(params[:id])
    end
  end

end
As this is a engine, overloading is pretty simple - but I must say that the great encapsulation of behaviour in the Beast, makes for an easy isolation of functional concerns, and the above use of before filters was almost all the customization that The Soup needed to integrate multiple forums. You can get Savage Beast here: Enjoy. If you have question please fwd by email. requires rails 1.2 and the latest engines plugin. http://svn.nnovation.ca/svn/savage_beast/trunk ------------------------------------------------------------------------ With help from Nick Coyne, we've nailed down a number of gotcha's when integrating Savage Beast, and even come up with a demo application you can use to learn the rules for integrating. The demo app is at: http://svn.nnovation.ca/svn/savage_beast_demo/ (it svn externals savage_beast) Below are more notes that will aid in integration: The demo app uses acts as authenticated (see the routes file for signup/login/logout urls - not included in the user interface) In the demo app, you'll want to grab the migration "003_add_post_count_to_user.rb" - this migration adds 2 columns to your user table that beast wants - I'll eventually include them into the savage_beast plugin. In the demo routes file, you'll also notice:
1
2
3

  #get routes for beast
  map.from_plugin :savage_beast
which gets all routes that beast depends on. The remaining routes in the demo are only there for the app (not the forum). You'll also want to add include SavageBeast::UserInit to your user model - gets a bunch of dependent methods for beast - take a look at the lib, and over-ride what's important to you (like user.display_name, admin? and logged_in?) As a final note, there are three controller before_filters that you'll want to over-ride if you have custom routes/params. Take a look at:
1
2
3
4
5
6
7
8
9

ForumsController
 before_filter :find_or_initialize_forum

PostsController
before_filter :find_post

TopicsController
 before_filter :find_forum_and_topic
Overiding the above filters in your own TopicsController (etc) is a great way to embed the forum within custom urls. One final note - Beast depends on a few plugins: white_list, white_list_formatted_content, browser_filter - oh and SB requires engines. If you run into integration issues, or suggestions please let me know. thanx for your help Nick. These notes will eventually turn into real docs - for now, that's all I can provide. enjoy
Gotta a comment?

26 Responses to “savage beast”

  1. carlivar Says:

    This is interesting to me simply because it has made Beast more modular. Will Beast also function as normal, with a forum index, aside from any model associations?

  2. Jodi Says:

    Carl -

    The forums, topics, posts controller are essentially the same. You can do anything with SB that you’d do with the Beast. The implementation is up to you.

    Ie, if you want have the default action of your app display the index of whatever forum you want.

    make sense?

  3. Nick Says:

    Ok, downloaded and installed into my plugins folder. Now what?

    What should I be changing in order to have my beast available at /forum? I’m assuming some changes in my routes.rb, but what exactly?

    thx

  4. David Kennedy Says:

    I am endeavoring to gather together a bunch of Web 2.0 style modules and integrate them into a web application that serves many distinct domains using one monolithic database. I expected to use the Beast as the ‘bones’ of my forum feature. I’m new to Rails, but have studied ardently and still sometimes have a hard time with the ‘words’. You and I might be on the same path? What does the “hasone :forum, :as => :owner ” mean? Are you saying that there is only one forum scoped by ‘owner’ and to add more DISTINCT forums to this project you’d change this to hasmany? Thank you, David

  5. Nick Says:

    Jodi, I’m making some progress here, but I’m going to continue my questions at ruby-forum.com so that others might answer too.

    Cheers

  6. Jodi Says:

    David -

    the polymorphic hasone :forum, :as => :owner example (project), means that a Project hasone forum.

    But as you said, this could be implmented as a has_many -

    basically, the Forum model has a polymorphic relationship to any model - and it’s solidly defined as has_one (ie, a Forum only has one Owner). But the Owner may have more than one Forum.

    make sense?

    I’ve adjusted the posted above with some docs, plus the svn url to a demo app that show’s how to integrate.

    Let me know how I can make this plugin better.

  7. Dan Wilsson Says:

    Hi:

    http://svn.nnovation.ca/svn/savagebeastdemo/

    The above URL ask for username/password ?? what should I use for that?

    I have some more questions but I think most of the answer lies on the demo app so I would like to give that a try before shooting questions here.

    Regards

  8. Jodi Says:

    Woops. Dan, smartypants removed the underscores.

    we’ll try again with syntax markup just to be safe.

    1
    2
    
    
    http://svn.nnovation.ca/svn/savage_beast_demo/
    

    Nick has been pounding at it. I think there’s still some depenence on a User model. When I can free up some time, I’ll address this. Otherwise, as you can see from the demo, it’s integrates well.

    enjoy.

  9. Rajesh Metha Says:

    Jodi:

    Couple of questions …

    1. What SVN version of Beast are you using? Beast 1.0 is out and they have changed the multilingual option to use another plugin.
    2. How are you keeping in sync with Beast? using SVK or something similler? Josh and Rick seems to be adding bunch of new feature as they are no longer “worried” about 500 LOC “idea”.
    3. I would like to have role based user model, so when you mention dependency on User model what do you exactly mean? I was thinking of using Bill Katz authorization plugin is this a good idea? how did you solve your user/roles.. own code or some external plugin?

    Thanks again for savage_beast.

  10. Jodi Says:

    Rajesh -

    SB is presently a port of Revision: 299.

    SB will always be a step or so behind - the changes I make at this stage are manual - but somewhat minor. I have yet to find an easy way (non-manual) to integrate Beast changes.

    Tests on the changes are currently reliant upon the core Beast tests - but will eventually include SB specific tests. These tests will decrease the chances of me introducing a bug.

    SB stripped out the Beast Authentication module entirely - you can now use what you want. The only requirement is an expectation of a Model called User - I will be generalizing this, but I haven’t had any bumps. Nick is using the Authorization plugin - I haven’t heard any issues with it’s usage with SB.

    Please let me know what works, doesn’t. And as always, I’m happy to take patches.

  11. Rich Breton Says:

    I already have a post model and controller for a blog in my application. Is this gonna be a problem?

  12. Jodi Says:

    ahhh, namespaces.

    the SB Posts controller will be mixed in to your Controller (merged), and your existing controller will take precedence.

    This may cause problems as SB behaviour will not take place. Take a look at the plugin Controller and compare with your own. You should be able to predict the outcome.

    It’s still early in the game - I could choose unique model/controller names, but I’d rather not break too far from the Beast code.

    let me know how it goes Rich.

  13. Ofer Says:

    the SVN server seems to be refusing connection

  14. Jodi Says:

    I’m not seeing that problem Ofer -

    If you’re still having problems contact me by email.

    Jodi

  15. victor Says:

    Would it be possible to implement private messaging by associating a forum to the user class? How should I go about it?

  16. Max Lapshin Says:

    Sorry, but how can I add my own localization? I’ve added catalog ru to vendor/plugins/savage_beast/po and added there beast.po. Then changed “nl” in init.rb to “ru”, but nothing is going to be translated.

    Gettext is loading, I’ve uncommented the debug message.

  17. Jodi Says:

    victor: I’m using SB for this very purpose.

    define in User:

    has_one :forum, :as => :owner, :dependent => :destroy

    you’ll then have to figure out the rules for who can post into this user forum.

    Max:

    I haven’t tested nor tried to implement the localization features of beast. I suspect it’s likely because the beast.po isn’t being copied to the runtime dirs at init. I’d be happy to take a patch to get this working.

    Jodi

  18. lab Says:

    Where can I change the forumhomepath link, so that it goes to a page that I specify.

    This is the full context:

    <%= link_to _('Forums'), forum_home_path %>
  19. kazuum Says:

    anyone have any issue with the active record relationships? For some strange reason none of the helper methods are working, such as:

    forum.recenttopics.first.repliedat

    it crashes without knowing what “recent_topics” is.

  20. sazwqa Says:

    Well I m trying the Savage Beast demo application, but don’t know why engines are getting stuck all the time. May be somebody could help at this:

    => Booting Mongrel (use ‘script/server webrick’ to force WEBrick) server: invalid argument: -p –debug => Rails application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment… Rails final load path: . Rails final dependency load path: ./script/../config/../vendor/plugins/engines/lib enginizing plugin: engines from ./script/../config/../vendor/plugins/engines Plugin ‘engines’: starting load. Plugin ‘engines’: loaded. plugins is now: engines engines has started.

    after this there is no response and the server gets stuck, any reasons ?

  21. sazwqa Says:

    Well got the solution for the problem:

    It’s probably due to engines getting stuck on windows when rails is freezed. Once rails in unfreezed engines work as usual. Had no issues with this in Linux.

    One more thing engines have a issue with RSpec too.

  22. Tom Says:

    Have you considered posting this plugin to http://agilewebdevelopment.com/plugins?

  23. Bill Harding Says:

    Hey Jodi and all!

    I’ve got a beta version of Savage Beast 2.0 ready to roll. I put installation instructions on my blog: http://www.williambharding.com/blog/?p=100

    It is Rails 2.0 compliant and incorporates everything in the Beast trunk up through January 2008. It is still a work in progress, but it has been working for our site so far.

  24. Says:

    : …

  25. Rstevens Says:

    I am still having problems with this

  26. KnollaInvinia Says:

    Hello!
    Check out
    a marvelous search engine – Warning: Invalid argument supplied for foreach() in /var/www/html/links.php on line 17
    P.S. Yahoo – everything will be found! Google: nothing was really lost…

    Bye to everyone!

Leave a comment