Archive for the 'ruby' Category
Install Passenger (aka mod_rails) on a Plesk 10 System

On Plesk System it is sometimes a little bit tricky to install extensions which are not supported by Plesk itself.

Here is a way how to install phusion passenger ( aka mod_rails) on a host that is managed using Plesk 10 or greater.

First Step
Install passenger as descriped on Passenger Installation :

  1. gem install passenger
  2. passenger-install-apache2-module

For the second point the gcc c++, curl dev libs, apache dev libs must be installed. Use apt-get (debian based systems) or yast (Suse) etc for installation.

Second Step
You have to add a vhosts file to the configuration of the domain / subdomain:

  • Place it at for the main domain:

    conf/vhost.conf

    or at for subdomains:

    subdomains//conf/vhost.conf

  • Add the following lines given by passenger-install-apache2-module

    LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
    PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
    PassengerRuby /usr/bin/ruby

  • Add appropriate user and group for the execution of the webapplication like :

    PassengerDefaultGroup psaserv
    PassengerDefaultUser

    The default setting is nobody/nobody which does not work in general.

  • Change the Rails Environment:
    The default is production. If yout test or development add the following line:

    RailsEnv development (resp. test)

Third Step
Change the document root to the public directory of the rails application.
In Plesk 10 you can do this here:
Go to Control Panel der Domain/Subdomain => Websites&Domain

Attention
passenger-install-apache2-module and the original docs give you another setting for the vhost:


AllowOverride all # <-- relax Apache security settings
Options -MultiViews # <-- MultiViews must be turned off

This does not work with plesk! It results in the following error messages:
Syntax error on line xx of /srv/www/vhosts/xxx/subdomains/yyy/conf/vhost.conf: Illegal override option #
Syntax error on line xx of /srv/www/vhosts/xxx/subdomains/yyy/conf/vhost.conf: Illegal option #

This setting was succesfully installed on a Strato based Linux system.

Snow Leopard and Komodo

For debugging ruby stuff with komodo the ruby.debug library is necessary.
Unfortunately the version which is provided by komodo itself is only a 32-Bit version.
But MacOS 10.6 is now mainly a 64-bit operating system.

Solution:
* rename or delete the following directory:
/Applications/Komodo IDE.app/Contents/SharedSupport/dbgp/rubylib/1.8/

* make sure you have installed the XCode Extension for Snow Leopard and downloaded the latets update for it

* install the current version of ruby-debug-base via gem:
sudo gem install ruby-debug-base

This one builds a native extension for 10.6, thats why XCode is necessary. Otherwise gem will complain on missing headers etc: e.g.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can’t find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

Reduce Annoying “requires” in ruby’s irb

It is quite annoying to use require again and again while testing anything in irb.
For that purpose it is useful to create a file called .irbrc in the home directory.
Here simply write sth like this:

require ‘rubygems’
require ‘socket’

Now every time you start irb the packages are loaded by default.

For windows it is also necessary to have an appropriate HOME Variable pointing to the right directory.

Migration data types / column types

The data types or columns types as they are called are little bit hard to find for somebody who ist not yet really familiar with rails language.
Now here what I found about this:

The columns types are:

:integer
:float
:datetime – default format: ’2007-07-06 17:05:22′
:date – default format: ’2007-06-07′
:timestamp
:time
:text
:string
:binary
:boolean

According options are:
:limit, e.g. :limit => 32
:default, e.g. :default => “defaultvalue”
:null, e.g. :null => true means its nullable

and for native data types:
:precision, ??
:scale, ??