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.





