Archive for July, 2006

Streamlined generator for Rails

A couple of days recently I took a trial to Sreamlined, a plugin to generate associated relationship between existing models in Rails. I think Rails folks will interest to this strange project and be curious to think how fancy it can be. In my case, it got me totally hooked: since streamlined, I can directly get content and relationship of models by looking up database tables in streamlined view. Streamlined offers many corresponding methods in generating class to help you pick up which columns in relative tables you want to keep attention with. Add, select, modify, or delect data with such columns are certainly supplied.

Their work give me a big help, thank you. But at the beginning, I say ‘generate associated relationship’, that means assuming I can get an overview of logic between my existing models after sweeping over my rails app, namely it can automatically detect all over logic of my project. Then bring me a rational chart or tree in view, or even I can directly modify my app’s logic in this tree. Yet streamlined doesn’t support my imagine.

Anyway, this out of alpha release is only 0.0.2. Expect they can add up more fancy to it.

Keep in mind that Streamlined is for existing models, if your tables or models doesn’t exist, it will generate an error:

error  Before updating scaffolding from new DB schema, try creating a table for your model ()

Can’t find mysqld.sock?

Over two days streamlined caught my attention. I tried it, got nothing but instead a lot of achings. That made various sorts of problems corrupting Rails. I’ll continue to be up with it and hope they can fix their bug lately in future. After all now my rest of Rails apps run well.

I don’t scare of connecting problem since I think I really got it worked out on me. But My Rails ultimately teased to me:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

It can’t find out mysqld.sock though it perfectly run on early morning before I set up streamlined. So I edit /etc/my.cnf and change ’socket’ location in section to fix through this, but nothing happened. So I roughly

sudo ln -s  /var/run/mysqld/mysqld.sock /tmp/mysql.sock

mysqld.sock in /var/run/mysqld/ shares 755 mood. Then everything is ok! What a silent world.

That’s all~

How to use mod_fcgid to set up Rails app on Apache2

Yesterday I tended to install mod_fcgid on my apache2, instead of mod_fastcgi or mod_ruby because of some insecure pipe problem with the laters. And To be pride and surprised, the author of mod_fcgid is Chinese people, but that doesn’t help me to come over the problems I face, so I need to handle them on my own. I’d like to review what I encountered and am hoping to help other people who are humbled by this.

My machine deploy: Ubuntu dapper, apache 2.0.58, Ruby 1.8.4, Rails 1.1.4, (mod_fcgid 1.10, libtool, ruby1.8-dev)

1. Installing mod_fcgid

Here is the problems ever, if you don’t want to read this, you can read the next paragraph which is correct steps.

Download mod_fcgid 1.10 and follow the INSTALL.txt step by step. There I ever had two problems. I folllowed by INSTALL.txt and it returned error no matter what I did. So I think I need to reinstall apache2 statically to load mod_fcgid module. Follow INSTALL.txt and Line:


./configure --prefix=/usr/local/apache2 --enable-dav --enable-so
--enable--maintainer-mod --enable-shared=max --enable-module=most --enable-fcgid

then when adding

LoadModule fcgid_module modules/mod_fcgid.so

to my httpd.conf and restart my apache2, I got error,


Syntax error on line 233 of /usr/local/apache2/conf/httpd.conf:
module fcgid_module is built-in and can't be loaded

Note ‘–enable-fcgid’. That’s because I have already installed mod_fcgid statically, I can’t use LoadModule to load a static build-in module, get it? Because it is already statically installed in apache2, and LoadModule is used to load a dynamic module. That is the reason why it returned error. So I had to reinstalled apache2 by this below to dynamically load modules at latter day.


./configure --prefix=/usr/local/apache2 --enable-dav --enable-so
--enable--maintainer-mod --enable-shared=max --enable-module=most

Okay! Then needed to install mod_fcgid dynamically. Follow the INSTALL.txt file, I got an error again:

dlname not found in apache2/modules/mod_fcgid.la.

Yes, apache2 failed to build the mod_fcgid.so and it was not in apache2/modules directory. That problem is because of the version of libtool in apache2/build. After I update my libtool by

sudo apt-get install libtool

I still had same error. Oh I forgot although I installed libtool, but I needed to do this

sudo cp /usr/bin/libtool /usr/local/apache2/build

to override previous libtool in apache2.

Ok, this time we can reinstall mod_fcgid again by steps in INSTALL.txt and it can be correctly installed.

2. Using gem to install fcgi

Next we need to install fcgi by type:

sudo gem install fcgi

But the annoying error appeared again. Said:

ERROR:  While executing gem ... (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in
/usr/lib/ruby/gems/1.8/gems/libxml-ruby-0.3.6 for inspection.
ruby extconf.rb install libxml-ruby

That indicated me to install ‘ruby-devel’ package, named ruby1.8-dev, so type:

sudo apt-get install ruby1.8-dev
sudo gem install fcgi

Well, problem was resolved, again.

3. Setting up Rails app, such as typo

Set up your Rails app by refering this page, and add this code below in your httpd.conf (warsaw is localhost name)


LoadModule fcgid_module     modules/mod_fcgid.so

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /home/alex/httpd
    ServerName warsaw
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common

redirectMatch ^warsaw/blog$ http://warsaw/blog/
    redirectMatch ^warsaw/radiant$ http://warsaw/radiant/
    #redirectMatch ^/$ http://warsaw/blog

Alias /blog "/home/alex/httpd/typo/public/"
    Alias /radiant "/home/alex/httpd/radiant/public/"

<Directory "/home/alex/httpd/typo/public">
        Options All ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        AddHandler fcgid-script .fcgi
        RewriteBase /blog
    </Directory>

<Directory "/home/alex/httpd/radiant/public">
        Options All ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        AddHandler fcgid-script .fcgi
        RewriteBase /radiant
    </Directory>

<Location /blog>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    </Location>

<Location /radiant>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    </Location>
</VirtualHost>

Notice that you should change the ‘.htaccess’ file name to ‘htaccess’ in app’s public/ directory. If doesn’t, it will appear disgusting error again.

Reference:[Integrating typo, Using mod_fcgid for Ruby on Rails Applications, Ruby on Rails and Ubuntu, Installing Typo]


This personal blog of Zhenzhong Wang, is mainly about Ruby on Rails and my a little spark at a mere whim.

You can Subscribe to my blog here.

a