Installing CommunityEngine on Rails 2.1

CommunityEngineIn a previous post, I talked about why we chose CommunityEngine. And due to the lack of documentation and several issues I had, I thought it would be useful to go through the installation steps and handling 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:
    4. gem install rmagick --local
    5. Restart Windows

    Installation

    1. Create a new Rails app:
    2. rails community -d mysql
    3. Install the engines plugin:
    4. ruby script/plugin install git://github.com/lazyatom/engines.git
    5. Put the community engine plugin into plugins directory:
    6. git clone --depth 1 git://github.com/bborn/communityengine.git vendor/plugins/community_engine
    7. Create the databases:
    8. rake db:create:all
    9. Rename public/index.html to index_backup.html
    10. 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"
    11. Modify all environment files ('development.rb', 'test.rb', and 'production.rb') by adding:
    12. APP_URL = "http://localhost:3000"
    13. Modify your routes.rb by adding this after any of your own existing routes, but before the default rails routes:
    14. map.from_plugin :community_engine
      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'
    15. Generate the community engine migrations:
    16. ruby script/generate plugin_migration
    17. Migrate the database:
    18. rake db:migrate
    19. Run your tests:
    20. rake test
    21. Run CommunityEngine test:
    22. rake community_engine:test
    23. Start the server:
    24. ruby script/server
    25. Go to /signup to create a new user
    26. To set a user as admin:
    27. rake community_engine:make_admin email=user@foo.com
    28. 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:
    29. update users set activated_at = current_date where id = 1
    30. Enjoy!

    Common Issues

    • On Windows, if the app run 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 (check this). 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  "name")
        end  
      end
      
    • For more info, check the readme file of CommunityEngine: /vendor/plugins/community_engine/README.markdown

    Resources

    Did you like this article? Bookmark it:

    Related Articles

    Leave a Comment

    If you want to post code, do this:
    <pre><code class="ruby|javascript|css|html"> your code here </code></pre>