Ruby on Rails Cheat Sheet

Note this is for Rails 2.x, which is quickly being overwhelmed by 3.0 doc on the web.

Migration Examples

      ./script/generate migration add_posts
      ./script/generate migration add_user_id_to_posts user_id:string

Rake commands:

MySQL build errors

when running “cap [deployfile] ec2onrails:setup”  use aptitude install libmysqlclient15-dev

EC2 on Rails

There are two machines:

Controller: Where you are running the capistrano commands

Server: The EC2 instance where the app will be running (potentially multiple)

  1. Controller: sudo gem install ec2onrails
  2. Controller: suso gem install capistrano
  3. Controller:   svn checkout https://rsportzcvs.svn.cvsdude.com/Swooshdot/trunk
  4. Start Server instance(s) using ec2onrails AMI
  5. Controller: Edit config/deploy.rb
    1. Set scm_username/password
    2. set role :web,app,db,memcache to Server(s) public DNS name
    3. point ssh_options[:keys] to your ssh private key
  6. Controller: cap ec2onrails:get_public_key_from_server
    • If this doesn’t work, you probably don’t have the right private key
  7. Controller: cap ec2onrails:setup
  8. Controller: cap ec2onrails:db:set_root_password
  9. Controller: cap deploy:cold
  10. Server:
cd /mnt/app/shared  
s3cmd sync s3://rsportz-shared/ .

Assuming you previously ran “s3cmd –configure” and answered all the questions in a sane manner.

Note you only need to do steps 1, 2 and 6 once on your staging server (if all your instances share the same key), then repeat the following for each new instance

For a simple server test, do the following:

$ RAILS_ENV=development ruby script/server webrick

Evil 1.8.7-p248 hack

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p249.tar.gz
tar xvfz ruby-1.8.7-p249.tar.gz
cd ruby-1.8.7-p249/ext/openssl/
ruby extconf.rb
make  sudo make install
sudo cp -R /usr/local/lib/ruby/site_ruby/1.8/openssl* /usr/lib/ruby/1.8/

To check if you got it right:

# irb
irb(main):001:0> require ‘openssl’
=> true
irb(main):002:0> quit