$HOME/rails
Developing Rails requires your own, local, environment and preferably some more stable area to test out your application and to present it to others.
To develop Rails you need local development environment. All workstations at department have been pre-configured. If you want to use your own environment (recommended), see notes in this document and or google "windows ruby on rails".
You can use your own server in your closet or use rails.cs.helsinki.fi
For this course we have rails.cs.helsinki.fi
virtual server. It's accessible only the CS Depts network. Use ssh-tunnels or such if you need to access it from outside.
username.rails.cs.helsinki.fi
launches application from /home/username/rails
.(Currently) you need to have these environment variables set for Rails related commands:
export RUBYLIB=$RUBYLIB:/opt/rubygems-1.3.5/lib export GEM_HOME=/opt/rubygems-1.3.5/gems export PATH=$PATH:/opt/rubygems-1.3.5/bin:/opt/rubygems-1.3.5/gems/bin (UPDATED)
Some notes for your closet or general interest.
Ruby interpreter is usually provided as system package. Currently it's safe bet to use MRI.
Any version above 1.8.6 patchlevel > 100 should be good. Ruby 1.9. or jRuby should also work.
Package management for Ruby. Latest RubyGems is always needed.
Depends on two environment settings: $RUBYLIB and $GEM_HOME. If you wish to install RubyGems in other directory than default then you need to specify these variables.
rails
" or "rake
"
Install with: gem install name-of-the-gem
Required and suggested gems:
rdoc
rake
rails
(with dependencies)mongrel
wirble
for colors in IRBrspec
rSpec testingrspec-rails
rSpec for RailsDatabase connection adapters:
sqlite3
for SQLite (sqlite3-ruby
for non-native implementation)pg
for PostgreSQL (postgres-pr
for non-native implementation)mysql
Cucumber testing
Select a database that you are familiar with. I would recommend PostgreSQL.
rails.cs.helsinki.fi
After logging, wait 1-3minutes, after that there should be mysql/postgres-password.txt in your home directory.
Automatically generated database is named after your username.
Automatically generated database is named after your username.
db.cs.helsinki.fi
It is possible to run database on alkokrunni, but please use rails.cs.helsinki.fi
. These instructions are just for situations where you need to test somethings / primary service is down for some reason.
Run /usr/local/sbin/userport <service>
to get port number for your account and service, e.g. /usr/local/sbin/userport postgres
postgres/
-directory in your $HOME
wanna-postgres
and give any password for superuser.$HOME/postgres/var/postgresql.conf
to have listen_addresses = '*'
instead of 'localhost'$HOME/postgres/var/pg_hba.conf
to have host all all 0.0.0.0/0 md5
to allow IPV4 connections from all hosts (inside cs-dept).start-postgres
, stop with stop-postgres
telnet db <your userport>
psql
to create user accountMySQL runs from $HOME/mysql/
and configuration is at$HOME/.my.cnf
Do not start MySQL with start-mysql
, as it has networking disabled by default!
$HOME/.my.cnf
to include:
[mysqld] ... port=<userport for mysql> bind-address=128.214.9.149where that IP address is the IP of
db.cs.helsinki.fi
.
mysqld_safe
, after startup suspend with ctrl+z
and resume execution in background with bg
. If it wont start error messages are at $HOME/mysql/var/alkokrunni.err
mysqld_safe &
kill mysqld
is the easiest way to stop MySQL.telnet db <userport>
mysql -u root -p
create user 'username' identified by 'password'; create database nameofthedatabase; grant all on nameofthedatabase.* to 'username'@'%';
Using Oracle with Rails is a bit hard, so let's not use it :)
After setup we can finally actually do something.
rails
-generator is configured to use SQLiterails -d postgresql <application_name>
config/database.yml
development: adapter: mysql/postgresql encoding: utf8 reconnect: false database: <nameofthedatabase or username at rails.cs.helsinki.fi> pool: 5 username: <username> password: <password> host: <rails.cs.helsinki.fi or db> port: <userport, or remove whole line to use default>
rake db:version
, that should exit without errors. If database hasn't been created yet (Postgres on DB?) then you can run rake db:create
or create it manually. You might also need to run rake db:migrate
.script/console
script/server
http://localhost:3000
Unlike Java, Rails is typically developed with (advanced) text-editor.
Server is configured so that username.rails.cs.helsinki.fi
will start Rails application of that user.
$HOME/rails
and ensure correct file permissions:
$HOME/rails/tmp/restart.txt
Test this setup with test application:
So now the full stack should be ready.
rake db:migrate
to see that SQLite3 worksrake spec
to see that rSpec works (9 examples, 0 failures).rake cucumber
to see that Cucumber integration tests are working. (1 scenario, 5 steps)script/server
and open http://localhost:3000
RAILS_ENV=production rake db:migrate
to see that SQLite3 works (and to create database in production environment)rake spec
to see that rSpec works (9 examples, 0 failures).rake cucumber
to see that Cucumber integration tests are working. (1 scenario, 5 steps)http://username.rails.cs.helsinki.fi
to verify that everything works