If you are using a plugin such as simple_captcha that requires RMagick, then you may encounter the following error during the rendering of jpeg catpcha image on Linux: (seen in the logs)
ArgumentError (unknown format: JPG):
/vendor/plugins/simple_captcha/lib/simple_captcha_image.rb:95:in `format='
This mean that we need to install the delegate library for JPEG.
1. do apt-get install libjpeg62 (not sure if this is required or just dev is enough)
2. do apt-get install libjpeg62-dev
3. cd to where you downloaded Imagemagick and do ./configure, make, make install.
The result of ./configure will summarize the status of deletgate libraries in the end.
After this, a blank image should start to show up in place of the simple_catpcha image and the logs may show something like this:
sh: gs: command not found
sh: gs: command not found
RMagick: unable to read font `(null)'.
RMagick: Postscript delegate failed `/tmp/magick-XXfm5AzA': No such file or directory.
sh: gs: command not found
sh: gs: command not found
RMagick: unable to read font `(null)'.
RMagick: Postscript delegate failed `/tmp/magick-XXg7z0RL': No such file or directory.
4. Do apt-get install ghostscript if simple_captcha image shows up as a white blank image, without any letters. Don't forget to do ./configure, make, make install from your Imagemagick source dir after this. Restarting of the server will be required for production environment.
Example result of ./configure status.
Delegate Configuration:
....
JPEG v1 --with-jpeg=yes yes
FreeType --with-freetype=yes yes
...
These 4 delegate libraries got simple_captcha working.
1. libfreetype6-dev (This also seems to be for fonts, but didn't cut it for simple_captcha, but I had installed it already, so I let it be.)
2. libjpeg62-dev
3. libpng12-dev ( installed it just in case...)
4. ghostscript
Running ./configure, make, make install from imagemagick source dir is necessary after installing the above libraries.
If captcha image is not getting recognized, you may need to run the following (for rails > 2.0, there is a separate command for older Rails which can be seen from the simple_captcha website.)
rake simple_captcha:setup
then run
rake db:migrate
Thursday, January 31, 2008
Getting simple_captcha image to show up on Ubuntu Linux
Solving ruby script/console "no such file to load -- readline" error
(These instructions are for Ubuntu for the error given below)
script/console
Loading development environment.
/usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require': no such file to load -- readline (LoadError)
from /usr/local/lib/ruby/1.8/irb/completion.rb:10
from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `require'
from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `each'
from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `load_modules'
from /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /usr/local/lib/ruby/1.8/irb.rb:54:in `start'
from /usr/local/bin/irb:13
1. apt-get install libreadline-ruby
2. apt-get install libreadline-dev
3. cd to where your downloaded source for ruby is located. (say ~/installed-software/ruby-1.8.6.tar.gz)
4. cd to ruby-1.8.6
5. run ./configure
6. run make
7. run make install
While running make, while the lines are streaming by, you will be able to notice 'compiling readline'.
8. try ruby script/console from your app dir. It should load it this time.
Posted by
Sonal
at
3:42 PM
6
comments
Links to this post
Labels: irb readline error, libreadline-ruby, Ruby on Rails, ruby script/console readline
Saturday, January 26, 2008
MySQL 5.1 Partitioning Example for Ruby on Rails Migration
- Creating table on mysql prompt : (separating partitions by 6 months each)

- In the migration file 001_create_stats.rb:

- After running rake db:migrate. On MySQL prompt, single partition being used in this example
- On MySQL prompt, two partitions being used in this example:
- On MySQL prompt, the default storage engine type is shown as InnoDB:

Posted by
Sonal
at
5:10 PM
1 comments
Links to this post
Labels: MySQL 5.1 for partitioning, MySQL partitioning for Ruby on Rails, Ruby on Rails
Friday, January 25, 2008
Upgrading MySQL 5.0.xx to MySQL 5.1.xx for InstantRails
MySQL 5.1 at this time is in release candidate state, but I thought I'd just check it out for its partitioning feature.
Preparation
- Take a mysqldump of the existing databases. You don't want to wipe out anything.
backup_dir> mysqldump --all-databases > backup.sql -u root -p
Enter password: ******** - Stop the InstantRails MySQL through the InstantRails Confirguration Interface (where Apache and MySQL server status shows?).
- Check using task manager, just in case the MySQL application is still running. No MySQL should be running. If you use any MySQL GUI tools such as MySQL Query Browser, close them too.
Installation of MySQL 5.1
- Downloaded mysql 5.1 setup exe (Windows ZIP/Setup.EXE (x86)) for Windows. I downloaded the 5.1.22 distribution.
- Cd to mysql-5.1.22-rc-win32 directory and click on setup.exe.
- This starts the MySQL setup wizard. Select 'typical' setup type and click Next, Next. This will start the installation in C:\Program Files\.
- The installation will additionally show another popup urging you to register, and that's upto you. In our main installation window, the installation has completed. The 'Configure the MySQL Server now' box is checked, and the next step is to click 'finish'. Click it.
- In the configuration popup, select Standard Configuration if you're a chicken like me or select Detailed Configuration otherwise. Here we are going with Standard Configuration.
- The next step shows two options, 'install as windows service' and 'include bin directory in windows path. I chose mySQL to be installed as a service. And checked the 'include bin dir..' box too. (I had encountered certain problems in starting up MySQL server on my Windows Vista when I did not choose to install it as a service.)
- The next step asks you to create a new root password, which you should do. I did not create an anonymous account, but just set the root password and moved on. I did not check the 'allow remote access'.
- Click 'execute' in the next screen and voila! Your firewall software may pop up a window asking you to allow the security settings execution to go through.
- Open Task Manager -> Services. MySQL is already up and running as a service. You can configure it so that it does not start automatically. (manual start).
- Open a brand new command window (not the one using InstantRails 'open a new console window' but using the start menu. There's a reason for it.) Key in mysql --version and it should show 5.1.xx. Key in the same in a Ruby console window got from InstantRails configuration and it should still show the previous verson of MySQL that your InstantRails is using.
Configure InstantRails to use MySQL 5.1
- Rename the mysql directory under InstantRails to say, mysql_old. (if you don't want to delete it)
- I use a program called junction to create a symlink, a la Windows style.
- Key in:
C:\Softwares\Junction>junction "C:\InstantRails\mysql" "C:\Program Files\MySQL\MySQL Server 5.1"
Junction v1.05 - Windows junction creator and reparse point viewerCopyright (C) 2000-2007 Mark RussinovichSystems Internals - http://www.sysinternals.com
Created: C:\InstantRails\mysqlTargetted at: C:\Program Files\MySQL\MySQL Server 5.1
C:\Softwares\Junction> - Now InstantRails's mysql path points to your MySQL 5.1 installation. Keying in mysql --version in this window now should show the new version of mysql.
- Modify database.yml for the new root password if you chose differently from your previous root password.
- In the Ruby console window, just for convenience, cd to directory where your backup.sql. Now start a mysql shell here. We want to recreate the databases from our old copy.
mysql -u root -p
password: ********
mysql> source backup.sql
... this will show tons of row creation info etc... hang on...
mysql> show databases;
... this should show all your old databases...
mysql> quit - Start InstantRails. For me, the InstantRails configuration window shows MySQL as stopped, but we know it is running as a service.
- Running rake db:migrate is not necessary since we have already created the databases with all the data brought in from the old tables.
Monday, January 7, 2008
Setting up Mongrel with Apache Proxy on Windows Desktop using Instant Rails
- cd C:/InstantRails/www. This is assuming your Instant Rails is installed in C:
- rails -d mysql myapp. This will create a new Ruby on Rails application in C:/InstantRails/www with MySQL as the default database server.
- On command prompt, key in: ruby script/server --port=3003. Check that you are able to access myapp at http://localhost:3003/ in your browser.
- Check that Apache is running by typing http://localhost/. This will display the index file fron C:/InstantRails/www directory.
- cd C:/InstantRails/apache/conf.
- Open http.conf file. In this file search for 'VirtualHost'. This will lead you to the bunch of virtualhost declations for typo and cookbook applications.
- httpd.conf with InstantRails has proxy_module already uncommented for use. LoadModule proxy_module modules/mod_proxy.s.
- Add myapp block to httpd.conf:

- In the InstantRails configuration tool, select Configure -> Windows Hosts File. Click it open and add an entry to the end: 127.0.0.1 myapp. Save the file and exit notepad.
- Restarting Apache server was not needed since I was running this set up for the development environment.
- Key in http://myapp/ in the browser to check that your app is indeed showing up the index.html page from myapp/public folder.
- As a further adventure, add up on myapp:
C:\InstantRails\www\myapp>ruby script/generate scaffold Blog blog_id:integer title:string body:text - Run rake db:migrate
- Now key in http://myapp/blogs and it should show up the 'index' action for blogs correctly. Browse around by clicking on 'new blog' and see that the page is served as http://myapp/blogs/new.
- Also look at Apache access logs from InstantRails application and also the mongrel server logs from the command line.
- If keying in http://myapp/ takes you to http://www.myapp.com/, then you need to checks Windows Hosts file using InstantRails.
- If keying in http://myapp/ takes you to the Index of / directory listing that just shows the files in myapp folder, then you need to make sure you have given the DocumentRoot in the virtualhost declaration in httpd.conf as C:/InstantRails/www/myapp/public/ and NOT C:/InstantRails/www/myapp/ alone.
- Alternatives: in httpd.conf file if you
(a) provide ServerName as http://www.myapp.com/,
(b) provide ProxyPass / http://localhost:3003/ instead of ProxyPass /myapp/ http://localhost:3003/, and
(c) include the entry 127.0.0.1 http://www.myapp.com/ in Windows hosts file,
you can access you application at http://www.myapp.com/ from your desktop. If the browser continues to show the real http://www.myapp.com/ then just restart the browser or perhaps just clear the browser cache. - It is not necessary to create your application under InstantRails/www. Having an application as InstantRails/rails_apps/myapp and providing the document root in httpd.conf as C:/InstantRails/rails_apps/myapp/public works just fine.
