Search

moon
Creative Commons License powered by blosxom valid xhtml 1.1 valid css FreeBSD Vim

 BREADCRUMBS: /home/weblog

Ruby on Rails - cookbook

According to http://www.rubyonrails.org/:

Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less code than most frameworks spend doing XML sit-ups

So far every framework I've ever encounted has sucked. But, of late, it's impossible to lurk on EFnet#freebsduk without somebody mentioning Ruby on Rails (or RoR) in a good light. So I've decived to bite the bullet and take Rails for a spin around the block.

Looking at my system the packages ruby18 and ruby-gems are already installed. And so is a very old version of the rails gem. No idea how that got there... but it takes only a few moments of not knowing what I'm doing to accidentally delete everything and to get the latest and greatest rails installed.

The article everyone seems to be using as light intro to RoR talks about Windows (with inherent backslash - not slash - wrongness), MySQLFront, expects Rails 0.9.4, and uses the builtin webserver. Well simply for the hell of it I'm going to use 0.9.5 (and FreeBSD, phpMyAdmin and Apache) and I'll wing it.

First Steps (and initial Apache config)

First this is to create the empty application:

rails ~/var/rails/cookbook

A quick test - by firing up the built-in WEBrick web server:

    cd ~/public_html/rails/cookbook
    ruby script/server --binding {actual ip}

then pointing my browser to:

    http://mybox:3000/

shows it's all working.

Setup of Apache is a breeze. In httpd.conf I just add:

  Alias /rails/cookbook /home/xaphod/var/rails/public

  <Directory /home/xaphod/var/rails/cookbook/public>
    Options ExecCGI FollowSymLinks
    AddHandler cgi-script .cgi
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>

A quick test shows it's working

MyTest (and mod_rewrite pain)

Once I get it through my thick skull - again - that the ONLamp article is using '\', not '/' it's simple to generate a new controller class.

ruby script/generate controller MyTest

However this fails miserably when I try it with my browser. Rails assumes I'm going to be running a unique vhost. I could. But I don't want to. A bit of mod_rewrite head-banging and I discover that in cookbook/public/.htaccess I just need to change this:

RewriteBase /dispatch.cgi

to this:

RewriteBase /rails/cookbook/dispatch.cgi

Editing my new controller is easy enough... once I find the correct file.

MySQL

The rest of the article is easy enough to follow. With the expection of the insistance on using MySQLFront. And people who casualy ignore the MySQL permissions model deserve all the pain they heap upon themselves. So unlike the ONLamp article I'll create MySQL user specifically to access my cookbook DB.

CREATE DATABASE `cookbook` ;
GRANT USAGE ON *.* TO cookbook@localhost IDENTIFIED BY "********";
GRANT ALL PRIVILEGES ON cookbook.* TO cookbook@localhost WITH GRANT OPTION ;

And I'll create my DB the easy way:

CREATE TABLE recipes (
  id int(10) unsigned NOT NULL auto_increment,
  title varchar(255) NOT NULL default '',
  description varchar(255) NOT NULL default '',
  date date NOT NULL default '0000-00-00',
  instructions text NOT NULL,
  category_id int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (id),
  UNIQUE KEY title (title)
) TYPE=MyISAM AUTO_INCREMENT=1;

CREATE TABLE categories (
  id int(10) unsigned NOT NULL auto_increment,
  name varchar(50) NOT NULL default '',
  PRIMARY KEY  (id)
) TYPE=MyISAM AUTO_INCREMENT=1;

Once I'm done the rest is, as I said, easy enough.


timestamp: 2005-02-03 11:53 | bikeshed this post | date link | file link

timestamp: 2005-02-03 11:53
URL:http://lizard.org.uk/weblog/freebsd/ruby/rails01.html

Thought for the Day

Figures recently released by the Israeli Government reveal a marked rise in anti-Semitic attacks in Britain. Sixty years after the holocaust, the greatest crime of the twentieth century, the curse of anti-Semitism continues to haunt us.

Christians often engage with the holocaust by celebrating the courage of other Christians who resisted the Nazis: Deitrich Bonhoeffer, Martin Niemoller, Edith Stein. But the truth is, they were rare exceptions.

For centuries, many Christians have stoked the fires of anti-Semitism with lies and slander. Jews were blamed for the death of Christ. Some believed that Jews practiced child sacrifice. The 4th century saint and theologian Gregory of Nyssa called the Jews "companions of the devil, accursed, detested, enemies of all that is beautiful".

Martin Luther went even further: "We are at fault in not slaying them," he said "Rather we allow them to live freely in our midst despite all their murdering, cursing, blaspheming, lying." He went on to advise Christians to "set fire to their synagogues and schools and to bury and cover with dirt whatever will not burn."

These days, Christians are ashamed by such words. But it's still terribly important to remember them.

For mostly, when we recall the Holocaust, we are invited to identify ourselves with the victims. My worry about this is that it protects many of us from the much more disturbing thought that we may have something in common with the perpetrators. Placing oneself alongside the victim may leave intact a fundamental complacency about our own potential for violence and hatred. The idea that we might catch a glimpse of our own reflection in the face of a Nazi guard is a terrifying thought - but one that is more likely to lead to genuine transformation than a cheap identification with the victim, which, too often, is more about telegraphing our own compassion for others to see.

Often, of course, we protect ourselves from the thought our own capacity for wickedness by describing wickedness as something foreign and alien. That's the problem with our tendency always to use the Nazis as the default example of human evil. It encourages the thought that evil is done by people with funny accents and sinister uniforms, people who lived in the past, people very different from us. But as Eric Fromm once put it: 'As long as one believes that the evil man wears horns, one will not discover an evil man'.

The most terrifying message of European anti-Semitism is that evil is perpetrated by ordinary, apparently respectable men and women with nice families and good taste in wine and music. In other words: by people like you and me. Those who refuse to face it are often the most dangerous people of all.

Dr Giles Fraser
BBC Radio 4 Today Programme
Thought for the Day
3 February 2005

timestamp: 2005-02-03 10:35
URL:http://lizard.org.uk/weblog/relevant/quotes/t20050203.html