Installing CommunityEngine on Rails 2.1

0

 

In a previous post, I talked about why we chose CommunityEngine. And due to the lack of documentation and several issues I faced, I thought it would be useful to go through the installation steps and the handling of some issues.

Requirements

Required gems

  • Rails 2.1.0
  • rake 0.8.1
  • rmagick
  • hpricot
  • htmlentities
  • RedCloth
  • haml
  • aws-s3 (if using Amazon S3 for photos)

Notes for Windows users

  • hpricot:
    gem install hpricot ––source http://code.whytheluckystiff.net
  • rmagick:
    1. Download the latest version of rmagick-win32. At the time of writing, it is RMagick-2.6.0-ImageMagick-6.4.3-6-Q8.zip
    2. Extract the zipped file and run the installer
    3. Install the gem you downloaded:
      gem install rmagick --local
    4. Restart Windows

Installation

  1. Create a new Rails app:
    rails community -d mysql
  2. Install the engines plugin:
    ruby script/plugin install git://github.com/lazyatom/engines.git
  3. Put the community engine plugin into plugins directory:
git clone --depth 1 git://github.com/bborn/communityengine.git vendor/plugins/community_engine

       4. Create the databases:

     rake db:create:all

 

       5. Rename public/index.html to index_backup.html

       6. Modify your environment.rb to look like the following:

RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
Rails::Initializer.run do |config|

#resource_hacks required here to ensure routes like /:login_slug work
config.plugins = [:engines, :community_engine, :white_list, :all]
config.plugin_paths += ["#{RAILS_ROOT}/vendor/plugins/community_engine/engine_plugins"]
...
end
require "#{RAILS
_ROOT}/vendor/plugins/community_engine/engine_config/boot.rb"

7. Modify all environment files ('development.rb', 'test.rb', and 'production.rb') by adding:

 

       APP_URL = "http://localhost:3000"

 

8. Modify your routes.rb by adding this after any of your own existing routes, but before the default rails routes: 

      map.from_plugin :community_engine

      map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

 

9. Generate the community engine migrations:

 

      ruby script/generate plugin_migration

 

10. Migrate the database:

 

       rake db:migrate

 

11. Run your tests:

 

       rake test

 

12. Run CommunityEngine test:

 

       rake community_engine:test

 

             13. Start the server:

       ruby script/server

 

             14. Go to /signup to create a new user

             15. To set a user as admin:

      rake community_engine:make_admin email=user@foo.com

 

             16.To activate the user, follow the activation link sent in the email (or appeared in the log after creating the user) or use this query:

      update users set activated_at = current_date where id = 1

 

             17. Enjoy!

Common Issues

  • On Windows, if the app runs without any css and the console shows a warning "Couldn't create the public file structure for plugin 'community_engine'", modify engines.rb,line 147 to be:
    base_target_dir = File.join(destination, File.dirname(source_files.first).gsub!(source, ""))
    • If you get a warning: DEPRECATION WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library will be REMOVED FROM RAILS 2.2, do this:
      gem install mysql

    Customization

  • Do NOT edit any file of CommunityEngine plugin so you can replace it when updates are available in the future.
  • You can edit app/config/application.yml to override the default configuration defined in /vendor/plugins/community_engine/engine_config/application.yml.
  • Any views you create in your app directory will override those in /vendor/plugins/community_engine/app/views.
  • Creating an identically-named controller in your application's app/controllers directory mixes your code with CommunityEngine's (your code takes precedence).
  • To mix models code, you must require the CommunityEngine's model first. Otherwise, your model would completely replace CommunityEngine's. For example: app/models/country.rb
    require_dependency "#{RAILS_ROOT}/vendor/plugins/community_engine/app/models/country.rb"
    
    class Country < ActiveRecord::Base  
      def self.find_countries
        find(:all, :order => "name")
      end  
    end
    

 

For more info, check the readme file of CommunityEngine: /vendor/plugins/community_engine/README.markdown

Resources

 Written By:

Hatem Mahmoud (www.expressionlab.com)

Post a Comment

eSpace podcast Prodcast

RSS iTunes