- Integrating Beast within another application In RubyOnRails, 486 days ago
-
Yesterday I did integrated the Beast forum engine into my old application Scrive.it.
Beast is a nice piece of software, very well written. It uses Ruby on Rails, so does my application, but it is not written with integration in mind (and I think it should, because many forums need to be integrated into an already existant application as a feature).
This integration assumes that the forum and the application reside under the same web domain (that is forum.scrive.it and www.scrive.it, for me). This is important because in that way one could share the same user codebase and provide a seamless login between those applications.
So, these are the steps I did:
- I created a new database for Beast, and installed it. I’ve to assure that the mysql user that accesses Beast database can access the other application database as well (reading and writing); see below
- assure that Beast and the Application use the same session identifier. This goes in the application controller or in environment.rb of the applications
session :session_key => '_scrive_session_id'- Beast and my application use ActiveRecord to store session data. So, they have to share the same session table. This goes in applications’ application.rb or environment.rb as well.
Session = CGI::Session::ActiveRecordStore::Session Session.set_table_name "scrive.sessions"- I imported all the Scrive users into Beast with a simple SQL statement “insert into users (id, …) select id, … from scrive.account”. I do not need to import passwords: user login and signup will anyway being managed by scrive.
- Scrive stores in session an object (a model) that do not exist in Beast; I then needed to create an empty model for that object and put it in the models directory of Beast
- Start fresh, removing all your sessions table records
- I created, in Beast, a controller that will route all the beast user requests (login, logout, signup) to the Scrive ones (via simple redirect_to). Then, I’ve only to slightly modify Beast’s routes.rb
- I did modified the login and logout procedure of scrive, adding the saving and wiping of some Beast keys:
# User logged in session[:user_id] = @account.id session[:topics] = session[:forums] = {} # User logged out session[:user_id] = nil session[:forums] = session[:topics] = nil- When a new user registers in Scrive.it I have to insert the new user in the users table of Beast. Something like that:
Account.connection.execute("insert into scrive_forum.users (id, login, email, created_at, last_login_at, admin, display_name, updated_at, website, activated) values ('#{@account.id}', '#{@account.login}', '#{@account.email}', now(), now(), 0, '#{@account.login}', now(), '#{@account.web_site}', 1)")- Finally, in the config/environments/production.rb of the two applications I added
ActionController::Base.session_options[:session_domain] = 'scrive.it'- Remember to modify one or more Beast account to be admin (and then create Forums). Update admin field to 1.
Hope this helps.
- sol said:
thanks for this summary, less work for me since I’m going to do something similar.
I think this is a good approach since its pretty loosely coupled.Posted on 04/25/07 10:53 AM #
- Antonio Eggberg said:
Hi:
First of all thank you for the right up. Unfortunately I am not as lucky as you are in terms of getting it working..
I am in the development mode i.e. localhost so how should I solve the session problem. Must I need to have a real domain? is there a work around ?? cos the tip you provided doesn’t work for me. even if i run script/server -e production. The cookie always get set localhost and i cannot share the session with my other app.. I must be missing something stupid.Posted on 04/26/07 08:12 AM #
- joost baaij said:
Thank you very very much, this is exactly what I need!
Posted on 05/08/07 12:40 AM #
- Erich L Timkar said:
I found that, at least on EngineYard, that it may be necessary to set the following in the ApplicationController as well.
session :session_domain=>’domain.com’
…to ensure they are actually considered to be the same session from the “same” host.Posted on 05/11/07 09:28 PM #
Comments
commenting closed for this article
→ 61648624
→

