S0000100===================================================================== 0. Ruby 1. Rails 2. Installation on Debian 3. Installation on Windows 4. Simple example: an Addressbook 5. Modifying the MVC 6. Foreign keys 7. Passenger 8. Addressbook with http authentication 9. REST 10. REST Client (using http authentication) 11. Add crypt to REST Client 12. Addressbook with WebAuth 13. Using AWDwR 14. Other aspects of customisation E0000100===================================================================== S0100100===================================================================== sudo mkdir -p /var/chroots/rails-chroot sudo debootstrap etch /var/chroots/rails-chroot \ http://mirror.ox.ac.uk/debian sudo mount -t proc /proc /var/chroots/rails-chroot/proc E0100100===================================================================== S0100150===================================================================== sudo chroot /var/chroots/rails-chroot E0100150===================================================================== S0100200===================================================================== cat >/etc/apt/sources.list <<% deb http://mirror.ox.ac.uk/debian etch main contrib non-free deb http://debian-security.oucs.ox.ac.uk/security etch/updates \ main contrib non-free deb http://debian.oucs.ox.ac.uk/sysdev/etch stable general % cat >/etc/hosts <<% 127.0.0.1 localhost % cat >/etc/resolv.conf <<% search oucs.ox.ac.uk nameserver 163.1.2.1 nameserver 129.67.1.180 % apt-get update apt-get install locales echo en_US.UTF-8 UTF-8 >/etc/locale.gen locale-gen apt-get upgrade apt-get install debhelper build-essential dnsutils devscripts less E0100200===================================================================== S0100300===================================================================== apt-get install mysql-server ed /etc/mysql/my.cnf <<'%' g/3306/s//8116/gp w q % /etc/init.d/mysql stop /etc/init.d/mysql start mysqladmin -P 8116 -u root password PW4root mysql -P8116 -u root -p PW4root \q E0100300===================================================================== S0100400===================================================================== apt-get install ruby ri rdoc ruby1.8-examples libmysql-ruby (cd /usr/bin; ln -s irb1.8 irb) ruby -v; ri -v; rdoc -v; irb -v # I got: # ruby 1.8.5 (2006-08-25) [i486-linux] # ri v1.0.1 - 20041108 # RDoc V1.0.1 - 20041108 # irb 0.9.5(05/04/13) E0100400===================================================================== S0100500===================================================================== apt-get install rubygems gem -v E0100500===================================================================== S0100600===================================================================== gem update --system E0100600===================================================================== S0100650===================================================================== ls -l /usr/bin/gem1.8 rm /usr/bin/gem ln -s /usr/bin/gem1.8 /usr/bin/gem gem -v; ri -v; rdoc -v # I got: # 1.1.1 # ri v1.0.1 - 20041108 # RDoc V1.0.1 - 20041108 E0100650===================================================================== S0100700===================================================================== gem install rails --include-dependencies # I got: # INFO: `gem install -y` is now default and will be removed # INFO: use --ignore-dependencies to install only the gems you list # Bulk updating Gem source index for: http://gems.rubyforge.org # Bulk updating Gem source index for: http://gems.rubyforge.org # Successfully installed rake-0.8.1 # Successfully installed activesupport-2.1.0 # Successfully installed activerecord-2.1.0 # Successfully installed actionpack-2.1.0 # Successfully installed actionmailer-2.1.0 # Successfully installed activeresource-2.1.0 # Successfully installed rails-2.1.0 # ... E0100700===================================================================== S0100800===================================================================== rails -v # I got: # Rails 2.1.0 E0100800===================================================================== S0400800===================================================================== mkdir /var/apps cd /var/apps E0400800===================================================================== S0400900===================================================================== rails -d mysql contacts cd /var/apps/contacts ls E0400900===================================================================== S0401100===================================================================== cd /var/apps/contacts/config cat database.yml cat >database.yml <<% development: adapter: mysql port: 8116 encoding: utf8 database: contacts_development username: ruby password: PW4ruby # Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. test: adapter: mysql port: 8116 encoding: utf8 database: contacts_test username: ruby password: PW4ruby production: adapter: mysql port: 8116 encoding: utf8 database: contacts_production username: ruby password: PW4ruby % E0401100===================================================================== S0401150===================================================================== mysql -P 8116 -u root -p mysql <<% grant all privileges on contacts_development.* \ to ruby@localhost identified by 'PW4ruby'; grant all privileges on contacts_production.* \ to ruby@localhost identified by 'PW4ruby'; grant all privileges on contacts_test.* \ to ruby@localhost identified by 'PW4ruby'; flush privileges; \q % PW4root E0401150===================================================================== S0401200===================================================================== cd /var/apps/contacts rake db:create:all E0401200===================================================================== S0401300===================================================================== cd /var/apps/contacts ruby script/generate scaffold Phone \ name:string \ number:string E0401300===================================================================== S0401350===================================================================== cd /var/apps/contacts/db/migrate cat *_create_phones.rb E0401350===================================================================== S0401380===================================================================== class CreatePhones < ActiveRecord::Migration def self.up create_table :phones do |t| t.string :name t.string :number t.timestamps end end def self.down drop_table :phones end end E0401380===================================================================== S0401400===================================================================== cd /var/apps/contacts rake db:migrate E0401400===================================================================== S0401450===================================================================== mysql -P 8116 -u root -p contacts_development <<% show create table phones; select * from phones; \q % PW4root # I got no output from the select because the table exists but is empty E0401450===================================================================== S0401500===================================================================== cd /var/apps/contacts ruby script/server -p 8119 & # I got: # => Booting WEBrick... # => Rails application started on http://0.0.0.0:8119 # => Ctrl-C to shutdown server; call with --help for options # [2008-05-31 12:16:11] INFO WEBrick 1.3.1 # [2008-05-31 12:16:11] INFO ruby 1.8.5 (2006-08-25) [i486-linux] # [2008-05-31 12:16:11] INFO WEBrick::HTTPServer#start: pid=28586 port=8119 E0401500===================================================================== S0401600===================================================================== ps -ef | grep ruby E0401600===================================================================== S0401650===================================================================== kill -KILL PPP E0401650===================================================================== S0401700===================================================================== http://www.abcd.ox.ac.uk:8119/phones E0401700===================================================================== S0401800===================================================================== http://www.abcd.ox.ac.uk:8119/phones/new E0401800===================================================================== S0401900===================================================================== http://www.abcd.ox.ac.uk:8119/phones/1 E0401900===================================================================== S0402000===================================================================== http://www.abcd.ox.ac.uk:8119/phones/1/edit E0402000===================================================================== S0500100===================================================================== class PhonesController < ApplicationController def index @phones = Phone.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @phones } end end ... end E0500100===================================================================== S0500200=====================================================================
| Name | Number | |||
|---|---|---|---|---|
| <%=h phone.name %> | <%=h phone.number %> | <%= link_to 'Show', phone %> | <%= link_to 'Edit', edit_phone_path(phone) %> | <%= link_to 'Destroy', phone, :confirm => 'Are you sure?', :method => :delete %> |
hello
% http://www.abcd.ox.ac.uk:8110/hello.html rm /var/www/hello.html E0700250===================================================================== S0700300===================================================================== apt-get install ruby1.8-dev gem install passenger E0700300===================================================================== S0700350===================================================================== passenger-install-apache2-module E0700350===================================================================== S0700400===================================================================== cd /etc/apache2/mods-available cat >passenger.conf <<% RailsSpawnServer \ /usr/lib/ruby/gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server RailsRuby /usr/bin/ruby1.8 RailsEnv development % cat >passenger.load <<% LoadModule passenger_module \ /usr/lib/ruby/gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so % E0700400===================================================================== S0700500===================================================================== cd /etc/apache2/mods-enabled ln -s /etc/apache2/mods-available/passenger.conf . ln -s /etc/apache2/mods-available/passenger.load . E0700500===================================================================== S0700600===================================================================== mkdir -p /var/www/apps ln -s /var/apps/contacts/public /var/www/apps/contacts E0700600===================================================================== S0700700===================================================================== cd /etc/apache2/sites-available ed default <<'%' $i RailsAutoDetect off RailsBaseURI /apps/contacts . w y % E0700700===================================================================== S0700800===================================================================== /etc/init.d/apache2 stop /etc/init.d/apache2 start E0700800===================================================================== S0700900===================================================================== http://www.abcd.ox.ac.uk:8110/apps/contacts/phones E0700900===================================================================== S0800100===================================================================== mkdir -p /etc/apache2/ssl apt-get install ssl-cert /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf \ /etc/apache2/ssl/apache.pem GB Oxfordshire Oxford University of Oxford The ABCD Department www.abcd.ox.ac.uk pat.lee@abcd.ox.ac.uk ls -lrt /etc/apache2/ssl/apache.pem E0800100===================================================================== S0800200===================================================================== cd /etc/apache2/mods-enabled ln -s /etc/apache2/mods-available/ssl.conf . ln -s /etc/apache2/mods-available/ssl.load . E0800200===================================================================== S0800300===================================================================== cd /etc/apache2/sites-available cp -p default ssl ed ssl <<'%' g/^NameVirtualHost \*/s//NameVirtualHost *:8113/p g/^