Archive for the 'Ruby' Category

Rails/Ruby's serialize rot after some time?..

Friday, September 19th, 2008

I have some very weird problems going on with some Ruby on Rails-driven sites on my server.. Basically, everything works perfect after my mongrel clusters just launched, but as time passes (and it could be hours or even days), "serialize" part of my apps start returning absolutely wrong values, don't return them at all, or just don't store values correctly.

It is all fixed by restarting Mongrels, but I wonder if anybody knows what's up with this problem? I tried different versions of ruby (currently running 1.8.6p287), and don't want to upgrade to 1.8.7 yet (have too many systems, some running on Rails 1.2…)

WTF is going on?…

Hold on with upgrading to ruby 1.8.6-p230!!

Thursday, June 26th, 2008

I started getting weird

(eval):2:in `protect_against_forgery?'

error from one of my Rails2-based system today. Mongrels were seg-faulting as well. The problem was quite unexpected as I have not touched the code for a while!

Turned out the problem was with the latest upgrade to ruby 1.8.6 patch level 230 (which is recommended by the Ruby on Rails site). And looks like this was the only system re-deployed (and restarted under new ruby version) since I have upgraded.

Now I'm back to p111, "vulnerable", but at least working version until problems sort themselves out.

Until they do, do not upgrade!

UPDATE:

Looks like the is a patch which addresses vulnerabilities which patch 230 addressed in turn. Check here for details. However, I'll just stick here for a couple of days for a real fix from the Ruby team.

Using RMagick to create cool photos

Wednesday, June 18th, 2008

Having something like this

Wouldn't it be cool if you could creating something like this?

All in real-time, in your Ruby on Rails project, using RMagick.

Hold on because I'll show you how. (more…)

Rails and readline problems on Mac OS X

Friday, October 19th, 2007

If you build Ruby on Mac OS X yourself, you may face the following problem once you have downloaded the language's source from ruby-lang.org, compiled/installed it and tried to run your Rails app:

 mike$ script/console

Loading development environment.

dyld: NSLinkModule() error

dyld: Symbol not found: _rl_filename_completion_function

  Referenced from: /usr/local/lib/ruby/1.8/i686-darwin9.0.0b5/readline.bundle

  Expected in: flat namespace

 

Trace/BPT trap 

 

 In order to fix the problem, you need to re-build readline from the source and then rebuild Ruby, linking it to the new readline's installation dir. Here's how you do it:

wget ftp://ftp.gnu.org/gnu/readline/readline-5.1.tar.gz 

tar -xzf readline-5.1.tar.gz

cd readline-5.1

./configure –prefix=/usr/local && make && sudo make install

 

and then rebuild Ruby (you do it in your Ruby source directory of course)

make distclean && configure –with-readline-dir=/usr/local && make && make install   

Once done, everything should be back on track. 

Override :destroy parameter in acts_as_tree in Rails

Thursday, September 20th, 2007

I have made a little extension (just function redefinition, actually) to allow you to control the behaviour of :destroy parameter in acts_as_tree function in Rails. More info, and download file follows.

This extension redefines the default behaviour of acts_as_tree function
to allow you to override the :dependent option for your trees
The default value defined in Rails is :destroy, but sometime you might want to use
a different cascade delete logic, or don't use cascade deleted at all.

Usage:
1. put this file into /lib/active_record_ext/ folder inside your rails application
2. add the following string somewhere in the environment.rb file:
require 'active_record_ext/tree'

This fix implements patch submitted to Rails development site, but not yet implemented
in main trunk of Rails. More info available at this link.

This extension should work without problems on Rails 1.2x, but of course I can not be held responsible
for any damage/loss/etc it might cause.

Download the extension patch (2Kb) 

Outputting resized attachment_fu image, stored in database, with RMagick

Tuesday, July 10th, 2007

I have recently started using attachment_fu plugin to store attachments (including images, of course) in database. attachment_fu provides functionality to create thumbnail images during upload, but you can't really foresee what thumbnail sizes you will need down the road, can't you?

That's why I decided not to make any thumbnails at all during the upload stage (except for basic resizing so I will not end up with 4K-pixels images in database.

I store all the images in database (easier to migrate, easier to backup) , which adds some level of complixity when you try to output stuff to the user.

Having all that, I wanted to be able to easily output page_cachable resized images. Here's how I have implemented it. (more…)

Dynamic setup of caches_page in Rails

Thursday, May 17th, 2007

Hot off the press! :) This blog entry will show you how to dynamically setup page caching in Rails, when you have a constantly growing list of actions you want to cache, but don't want to update caches_page's actions listing every time you add a new action which requires caching.. This is especially handy if you use FlexImage plugin for Rails. Read on if you're interested. (more…)

How to install Ruby, Rails, mySQL and Apache from (almost) the scratch

Tuesday, April 3rd, 2007

I've been installing everything that is needed to run Ruby on Rails application onto a host (which is CentOS 4.x), which didn't even have Ruby installed, mySQL was too old and Apache didn't have required modules for running Mongrel clusters. So I had to install everything from the scratch, and the whole process was documented so I could repeat it in the future :) But may be this will helpful to someone else too, so here it is, right from my Yojimbo's note :)
Just one thing to notice. CentOS already has some of the required libs installed (zlib, libpng, libjpeg and freetype), so if you don't have them installed, do it before proceeding. I think there are plenty of info on this matter so I'll omit it.

Now, to the business.

RUBY

wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5.tar.gz
tar zxvf ruby-1.8.5.tar.gz
cd ruby-1.8.5
./configure
make
sudo make install

Warning! If you're on Mac, you have to use the following string to configure Ruby install:

./configure –prefix=/usr/local –enable-pthread

On Mac OS X, once you have installed Ruby, you have to fix default paths for your default shell, because Ruby installs itself to /usr/local/bin by default, and Apple's default binaries location is in /usr/bin. Do this in Terminal:

pico ~/.bash_login

# and paste the following text:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
# save the file (Control-W) and relogin, or just re-open terminal session before proceeding.

RAILS : GEMS

wget http://rubyforge.rubyuser.de/rubygems/rubygems-0.9.2.tgz
tar zxvf rubygems-0.9.2.tgz
cd rubygems-0.9.2
ruby setup.rb

RAILS: CORE (possible to use –include-dependencies, but i was getting some 'not found' error with this option)

#install the specific version, which happens to be 1.2.2 in this case.
gem install -v=1.2.2 rails

RAILS: STANDARD STUFF (possible to use –include-dependencies)

gem install capistrano
gem install mongrel
gem install mongrel_cluster
gem install gettext
gem install unicode

APACHE 2 with load balancer (for Mongrel cluster)

wget http://ftp.kddilabs.jp/infosystems/apache/httpd/httpd-2.2.4.tar.gz
tar zxvf httpd-2.2.4.tar.gz
cd httpd-2.2.4
./configure –enable-rewrite –enable-proxy –enable-load-balancer –enable-mods-shared=ALL
make
sudo make install

GHOSTSCRIPT & FONTS

# we need to install/update ghostscript and install ghostscript-fonts in order to get rid of the "`get_type_metrics': unable to read font `(null)' (Magick::ImageMagickError)" error:

wget http://jaist.dl.sourceforge.net/sourceforge/ghostscript/ghostscript-8.56.tar.gz
tar zxvf ghostscript-8.56.tar.gz
cd ghostscript-8.56
./configure
make
sudo make install

wget http://jaist.dl.sourceforge.net/sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz
tar zxvf ghostscript-fonts-std-8.11.tar.gz
mv fonts /usr/local/share/ghostscript/8.56/

IMAGEMAGICK (required by RMagick)

wget ftp://ftp.u-aizu.ac.jp/pub/graphics/image/ImageMagick/imagemagick.org/ImageMagick-6.3.3-10.tar.gz
cd ImageMagick-6.3.3
./configure
make
sudo make install

RAILS: RMAGICK (manual install - I have always had multi-systems compatibility problems with the gem install)

wget http://files.rubyforge.mmmultiworks.com/rmagick/RMagick-1.15.4.tar.gz
tar zxvf RMagick-1.15.4.tar.gz
cd RMagick-1.15.4
./configure
make
sudo make install

MYSQL

wget http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.0/mysql-5.0.37.tar.gz
tar zxvf mysql-5.0.37.tar.gz
cd mysql-5.0.37
./configure –with-extra-charsets=all –prefix=/usr/local/mysql
make
sudo make install

#in /etc/my.cnf
[mysqld]
set-variable = max_allowed_packet=32M # I upload large images into DBs, therefore need a bigger allowed packet size

(also need to change encodings to utf8)
default-character-set=utf8

SUBVERSION (required to capistrano deployment to work)

wget http://subversion.tigris.org/downloads/subversion-1.4.3.tar.gz
wget http://subversion.tigris.org/downloads/subversion-deps-1.4.3.tar.gz
tar zxvf subversion-1.4.3.tar.gz
tar zxvf subversion-deps-1.4.3.tar.gz
cd subversion-1.4.3
./configure
make
sudo make install

That all folks :) Hope this was helpful.

RMagick::RVG : outputting an inline image (or the horrid no decode delegate for this image format `' error)

Thursday, March 8th, 2007

Ruby is all nice and all, but some things are just either very poorely documented or just don't work very seamlessly sometimes. I have spend over an hour today trying to identify what is going on with RMagick::RVG not wanting to output an inline image for me.

The error I was getting was:

no decode delegate for this image format `'

And the code was as simple as contents of my brain in the early morning:

Magick::RVG.dpi = 72

rvg = Magick::RVG.new(320, 320).viewbox(0,0,320,320) do |canvas|
canvas.background_fill = 'red'
end

img = rvg.draw

send_data img.to_blob,
:filename => "woohoo.png",
:disposition => 'inline',
:quality => 90,
:type => 'image/png'

Everything seems to be fine and as I'm setting the image type in the to_blog thingy, I somehow assume there should be no problems decoding the image. Well I was wrong! In order to get rid of the bloody no decode delegate for this image format `' you have to specify the image format you want to image to be in, manually.

Behold the magic!

Magick::RVG.dpi = 72

rvg = Magick::RVG.new(320, 320).viewbox(0,0,320,320) do |canvas|
canvas.background_fill = 'red'
end

img = rvg.draw

img.format = "png" #FORGET THIS LINE AND DIE A HORRIBLE DEATH!! :)

send_data rvg.draw.to_blob,
:filename => "woohoo.png",
:disposition => 'inline',
:quality => 90,
:type => 'image/png'

Well.. that's it :) Hopefully it will help someone to save an hour or two ;)

RadRails 0.6.2 is out!

Thursday, April 13th, 2006

Yeah! It's out and now where are those finger of mine to touch the new version? :)

OUT!