Mongoid presentations

When starting with mongoid I have missed a lot some demo source code.

How it works with controllers, does it plays nice with nested attributes, such things.

Here is presentation of mongo  and here are some slides


I writing this post for those who start using Mongo in their rails applications. I want to share my experience. First I discovered mongoid but then i saw mongo_mapper  – so I decide to go with the crowd. But! I was wrong. I there is no documentation for mongo_mapper but some blog posts arround, the examples are not aways working and you have to fight with all the code – I don’t maybe I have found some old documentation. When you dive in the code – again no documentation and not clear behaviour. Maybe it is a good solution but for me it doesn’t work. I lost 1.5 days experimenting and hoping that the things will go.

Then I give a try with mongoid. It has wonderfull documentation for starters also it seems at first glance that the code in mongoid is more readably and human friendly. It took me 2hours to port all my models to mongoid.

The guy developing mongoid seems pretty active.

last words – it is pleasure to work with mongoid – I recommend it to all.

Getting fast with rspec

get the gem from here


How to fix the Missing error


Rails 2.3.2+, memcached and logger

Finally our twitterized version of is ready. But! When in production – read with many connection – the memcached get overloaded by not closed connections and on 1024 it says

“accept(): Too many open file” and memcached dies.

After 1 day investigating the problem  we have found that the following line in the initializers is causing the problem


We havent investigating deeper but when commenting this line everything works fine.

We have tested with Rails 2.3.2 and 2.3.3 with memcache-client-1.7.4

My Ubuntu workstation configuration

XOrg configuration

  • cvt 1680 1050 75
  • xrandr –newmode …the output from cvt
    xrandr –newmode “1680x1050_75.00” 187.00 1680 1800 1976 2272 1050 1053 1059 1099 -hsync +vsync
  • xrandr –addmode DVI-0 1680x1050_75.00

Lenovo Y510

You have to install the latest alsa.

Then replace the existing kernel modules with the just build one. Then run depmod -a as point kilbasar here

sudo su
cd /lib/modules/2.6.22-14-generic/ubuntu/media/snd-hda-intel/
mv snd-hda-intel.ko snd-hda-intel.ko.bak
ln -s /lib/modules/2.6.22-14-generic/kernel/sound/pci/hda/snd-hda-intel.ko /lib/modules/2.6.22-14-generic/ubuntu/media/snd-hda-intel/snd-hda-intel.ko
cd /usr/src/alsa/alsa-driver-1.0.16rc2/modules
cp * /lib/modules/2.6.22-14-generic/kernel/sound/
depmod -a

Logitech Revolution MX

  • The mouse wheel control
    • Download from here or revoco-0.5.tar
    • make
    • sudo ./revoco manual=6
    • lets try to add it in ~/.xprofile next time
  • Here is my xorg.conf
Section "Monitor"
 Identifier "External DVI"
 # 1680x1050 74.89 Hz (CVT 1.76MA) hsync: 82.31 kHz; pclk: 187.00 MHz
 Modeline "1680x1050_75.00"  187.00  1680 1800 1976 2272  1050 1053 1059 1099 -hsync +vsync
 # 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
 Modeline "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
 # 1680x1050 69.88 Hz (CVT) hsync: 76.58 kHz; pclk: 174.00 MHz
 Modeline "1680x1050_70.00"  174.00  1680 1800 1976 2272  1050 1053 1059 1096 -hsync +vsync
 Option "PreferedMode"    "1280x1024_75.00"

Section "Screen"
 Identifier    "Configured Screen Device"
 Device    "Configured Video Device"
 SubSection "Display"
 Depth    24
 Modes "1680x1050" "1024x768" "640x480"
 Virtual    2960 1050

Section "Device"
 Identifier    "Configured Video Device"
 Option    "Monitor-DVI-0" "External DVI"

My Development setup commands

I noticed simillar post here

sudo aptitude install mc vim subversion screen pidgin meld curl links2 vim-ruby vim-gnome vim-doc vim-scripts vim-ruby vim-perl \
subversion git-core bluefish kompozer\
libmysqlclient15off libmysqlclient15-dev mysql-common mysql-client \
libmysql-ruby1.8 irb ruby1.8 rdoc ri rake \
apt-utils build-essential ruby1.8-dev mysql-server memcached libxslt1-dev libpcre3-dev zlib1g-dev unzip gzip mytop openssl \
libopenssl-ruby libmagick9-dev imagemagick librmagick-ruby1.8 imagemagick librmagick-ruby-doc  libmagick9-dev ruby1.8-dev \
libdbd-sqlite3-ruby libsqlite3-ruby sqlite3 libsqlite3-dev

ln -s /usr/bin/ruby1.8 /usr/bin/ruby

mkdir ruby_install
cd ruby_install
tar xzvf ruby*
cd rubygems-1.3.5
ruby setup.rb
cd ..
cd ..

ln -s /usr/bin/gem1.8 /usr/bin/gem

gem install rails mysql mongrel mongrel_cluster rails paperclip will_paginate andand \
json feed-normalizer hpricot mechanize ruby-debug uuid ruport ruport-util acts_as_reportable \
rufus-scheduler annotate openwferu-scheduler production_log_analyzer capistrano-ext libxml-ruby twitter capistrano wirble RedCloth
rspec-rails sqlite3-ruby \
--no-ri --no-rdoc

gem install rmagick -v 1.15.12
ruby -rrubygems -e "require 'RMagick'; puts Magick::Long_version;"

cat > /home/guda/.irbrc
require 'rubygems'
require 'wirble'
require 'logger'
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')

Gmail notification

What about

Rake mysql tasks

I have found that I should be quicker if I put the following task in all my small projects.
Continue reading

Mysql gem and the mkfm error

The mysql gem was removed from the rails 2.3.2. and you need to install it via the gem install mysql command
But! There is a problem compiling it. seems that the mysql cant find the libmysql are the options:
yum install openssl openssl-devel

Configure with path to mysql_config and install the mysql api via gem:

# cd /usr/lib/ruby/gems/1.8/gems/mysql-2.7
# ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
# make
# ruby ./test.rb [hostname [user [passwd [dbname [port [socket [flag]]]]]]]
# make install
# gem install mysql


And after that you can read the README.html located in the mysql gem directory :)


 sudo aptitude install libmysqlclient-dev libmysql-ruby  libmysql++-dev ruby-dev

ruby classes and instances override

module InstanceMethods
def an_instance_method
“You called an_instance_method on #{self.class}”


module ClassMethods
def a_class_method
“You called a_class_method_from_module on #{self}”

def b_class_method
puts “b_class_metbod”


class MyClass
include InstanceMethods
extend ClassMethods

def MyClass.a_class_method
puts “Mine class Method”

def an_instance_method
puts “Mine instance”

my_class =
puts my_class.an_instance_method
puts MyClass.a_class_method
puts MyClass.b_class_method

seesaw gem configuration

I cant find good examples and help in Internet for seesaw gem. Maybe it is used only by very experirienced rails persons.

I will publish my configurations in case they are helpfull to some one.

guda@guda-desktop:~/system3/config$ cat seesaw.yml 
restart_cmd: sudo kill -HUP `cat /usr/local/nginx/logs/`
config_symlink: http_cluster/cluster.conf
mongrel_config_path: /home/mongrel/system3/current/config/mongrel_cluster.yml
config_path: /home/mongrel/system3/current/config
  all: cluster_all.conf
  1: cluster_1.conf
  2: cluster_2.conf
symlink_cmd: ln -sf

here is where my nginx conf link points

guda@guda-desktop:~/system3/config/http_cluster$ ls -l
total 16
-rw-r--r-- 1 guda guda 152 2008-11-07 17:17 cluster_1.conf
-rw-r--r-- 1 guda guda 152 2008-11-07 17:17 cluster_2.conf
-rw-r--r-- 1 guda guda 277 2008-11-07 17:17 cluster_all.conf
lrwxrwxrwx 1 guda guda  66 2008-11-08 01:30 cluster.conf -> /home/mongrel/system3/current/config/http_cluster/cluster_all.conf

and in deploy.rb I have this task rewritten.

set :seesaw_conf, "#{current_path}/config/seesaw.yml"
namespace :deploy do
  desc <<-DESC
  Restart the Mongrel processes on the app server using seesaw
  task :restart, :roles => :app do
    run <<-CMD
      cd #{current_path} ; #{mongrel_rails} seesaw::bounce -C #{seesaw_conf}
#    send(run_method, "cd #{current_path}; #{mongrel_rails} seesaw::bounce -C #{seesaw_conf}")

I am not sure that this is the perfect way of configurating the seesaw. I think that I have some mistakes in the path configurations, and because of that I have to patch the capistrano restart task.

Installing notes for Rails on Debian/Ubunto

Debian Etch with backports

Add this line in sources.list to get rails > 1.8.5 in rails etch

deb etch-backports main contrib non-free
# deb etch-backports main contrib non-free
apt-get install debian-backports-keyring
aptitude update

# some ruby stuff
aptitude install -t etch-backports ruby1.8-dev libmysqlclient15off libmysqlclient15-dev mysql-common mysql-client libmysql-ruby1.8

# some system utils/libs
aptitude install apt-utils build-essential mysql-server mysql-common mysql-client memcached libxslt1-dev libpcre3-dev zlib1g-dev unzip gzip mytop  openssl

aptitude install -t etch-backports libopenssl-ruby

# gems
gem install rails mongrel mongrel_cluster -y

check this step-by-step

Image magick linux howto –

aptitude install libmagick9-dev  imagemagick librmagick-ruby1.8 imagemagick librmagick-ruby-doc  libmagick9-dev ruby1.8-dev

# for version 1 of imagemagick we use this rmagick, else try it without the -v
gem install rmagick -v 1.15.12 

# lets test it
> irb
require 'rubygems'
require 'RMagick'
puts Magick::Long_version

# or with 

ruby -rrubygems -e "require 'RMagick'; puts Magick::Long_version;" 

I love this tutorial on rubyinside

© 2024 Gudasoft

Theme by Anders NorénUp ↑