Fetching contributors…
Cannot retrieve contributors at this time
111 lines (77 sloc) 3.31 KB

Notes on MagLev and Rails 3

The files in this directory allow you to run the default Rails app on MagLev. MagLev serves static and dynamic pages on patched versions of Rails 3.0.x and 3.1.x.

This document discusses installing Rails 3.1.x. If you want to use Rails 3.0.x, you'll have to check out an earlier version of this document on GitHub.

Quick Start

  1. Make sure the MagLev repository is running:

    $ cd $MAGLEV_HOME
    $ rake maglev:start      # or: $MAGLEV_HOME/bin/maglev start
  2. Install Rails and patch it:

    $ cd $MAGLEV_HOME/examples/rails
    $ $MAGLEV_HOME/bin/bundle install
    $ rake patch:activesupport
  3. Setup the Database (see bottom of file for MySQL details):

    $ cd $MAGLEV_HOME/examples/rails/myapp
    $ $MAGLEV_HOME/bin/rake db:create
    $ $MAGLEV_HOME/bin/rake db:migrate
  4. Run the app:

    $ cd $MAGLEV_HOME/examples/rails/myapp
    $ $MAGLEV_HOME/bin/bundle exec rails server

    Then hit localhost:3000/

Rails on MagLev: Status

Rails runs on MagLev, but has not been fully tested, so there may still be some work to do. There are a few error messages that get printed, but you can safely ignore them (see

Progress towards full Rails Lifecycle

The following steps are loosely based on the Rails Blog Tutorial.

1. Install rails

Install rails:

$ cd $MAGLEV_HOME/examples/rails
$ $MAGLEV_HOME/bin/bundle install

You will need to patch activesupport. The patches directory has patches for rails 3.1.0 and a few prior releases.

$ cd $MAGLEV_HOME/examples/rails
$ rake patch:activesupport

2. Create and configure new rails app

Generate the application:

$ MAGLEV_HOME/bin/bundle exec rails new myapp

And configure the database:

$ cd myapp
$ $MAGLEV_HOME/bin/bundle exec $MAGLEV_HOME/bin/rake db:create

3. Start server

$ $MAGLEV_HOME/bin/bundle exec rails server

4. Generate new controllers and scaffolding


$ $MAGLEV_HOME/bin/bundle exec rails generate controller home index

If you remove public/index.html and add the following into config/routes.rb, you should be able to hit localhost:3000/ and see home#index

root :to => "home#index"

5. More Scaffolding and Running migrations

You can also create scaffolding and run migrations:

$ $MAGLEV_HOME/bin/bundle exec rails generate scaffold Post name:string title:string content:text
$ $MAGLEV_HOME/bin/rake db:migrate

You should now be able to start the server and hit localhost:3000/posts and start managing your blog.

MySQL details

To use MySQL, you'll have to use the ruby-mysql gem instead of the mysql2 gem. To create an app that does that, do:

$ $MAGLEV_HOME/bin/rails new myapp --database=mysql --skip-bundle

Then edit the Gemfile and change

gem 'mysql2'


gem 'ruby-mysql', :require => 'mysql'

Edit myapp/config/database.yml

A. Change <tt>mysql2</tt> to +mysql+.
B. You may also need to add the +socket+ option to talk to your
   server, it it isn't listening on <tt>/tmp/mysql.sock</tt>, e.g.:
       socket: /opt/local/var/run/mysql5/mysqld.sock
C. Change the +username+, +password+ and +database+ for your

Then run bundle:

$ cd myapp
$ $MAGLEV_HOME/bin/bundle install