| created: 4/3/2008 |
updated: 5/22/2008 |
|
Merb
Merb is the best framework for building Ruby web applications. It has a concise core that you can augment with RubyGems. It is faster, smaller, and more flexible than alternate Ruby frameworks, such as Ruby on Rails.
gem install merb
Merb also has some helpers that are very useful.
gem install merb_has_flash merb_helpers
SQLite
I love the simplicity of working with an SQLite database. The libsqlite3-dev package is an unapparent prerequisite of DataMapper.
aptitude install sqlite3 libsqlite3-dev libsqlite3-ruby -y
I use DataMapper for the model.
gem install datamapper do_sqlite3 merb_datamapper
I use Thin for serving.
gem install thin
Generate a merb application
merb-gen app appname
Create SQLite databases
cd appname
mkdir db
vim config/init.rb
a
### Uncomment for DataMapper ORM
use_orm :datamapper
esc :wq
merb-gen
mv config/database.yml.sample config/database.yml
vim config/database.yml
---
:development: &defaults
:adapter: sqlite3
:database: db/development.sqlite3.db
:test:
<<: *defaults
:database: db/test.sqlite3.db
:production:
<<: *defaults
:database: db/production.sqlite3.db
esc :wq
merb-gen resource resourcename column1name:string column2name:string
rake dm:db:automigrate
rake MERB_ENV=test dm:db:automigrate
rake MERB_ENV=production dm:db:automigrate
Start a local merb application for development
cd applocation/appname
merb
Stop a local merb application
cntl c
Start a production merb application at a specified location, with 2 thin app servers, as daemons, starting at port 4000
merb -e production -m applocation/appname -c 2 -a thin -d -p 4000
Stop any merb daemons within an application
cd applocation/appname
merb -K all
Nginx
I use the http server Nginx, because it is small, easy to configure, and very fast.
aptitude install nginx -y
Add a site that proxies to two web applications.
vim /etc/nginx/sites-available/sitename
upstream sitename {
server 127.0.0.1:4000;
server 127.0.0.1:4001;
}
server {
listen 80;
server_name www.sitename.com;
rewrite ^(/.*) http://sitename.com$1 permanent;
}
server {
listen 80;
server_name sitename.com;
location / {
proxy_pass http://sitename;
}
}
Enable the site
ln -s /etc/nginx/sites-available/sitename /etc/nginx/sites-enabled/sitename
/etc/init.d/nginx restart