Archive | Rails RSS feed for this section

capybara rspec selenium – slow down the test so you can see alert boxes etc

6 Nov

saw this somewhere and wanted to record it…

require 'selenium-webdriver'
module ::Selenium::WebDriver::Remote
class Bridge

    def execute(*args)
result = raw_execute(*args)['value']
sleep 0.5

Multi lingual support in MySQL/Rails/BASH

16 Apr

We had translations in text files that we needed imported into our mysql database.

Our database had UTF-8 character encoding which is correct.

Swedish characters were appearing like :åäà �
There are a number of issues here:
1. SSH session – if you’re using Putty make sure you’ve set the terminal to be UTF
2. check the type of your file using “file”
3. if necessary use ‘iconv’ to convert to UTF8 – iconv -f ISO-8859-1 -t UTF8 /tmp/fr2.yml
4. Ensure your browser is displaying UNICODE, View->Character Encoding in Firefox
5. If you are using Linux, make sure a UTF LANG is set eg.: export LANG=”en_AU.UTF-8″ pain

17 Sep

We are using rmagic 1.15.11 gem which is inside our source tree.

On CentOS i had installed:
rpm -qa | grep -i magick

But when i tried to run mongrel I got:

#<noMethodError: undefined method `configuration' for #>
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- (MissingSourceFile)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /home/jtsoong/chipmeup/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:509:in `require'
from /home/jtsoong/chipmeup/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:354:in `new_constants_in'

I then downloaded the tar ball of ImageMagick (the same version 6.4.3-6) and installed that (straight ./configure; make; make install)

I then got this error:
/usr/lib/ruby/gems/1.8/gems/rmagick-2.6.0/lib/ /usr/lib/ruby/gems/1.8/gems/rmagick-2.6.0/lib/ undefined symbol: Init_RMagick - /usr/lib/ruby/gems/1.8/gems/rmagick-2.6.0/lib/ (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'
from /home/jtsoong/chipmeup/vendor/rails/activerecord/lib/../../activesupport/lib/act

To fix this I linked in the new (in actual fact the new gem had created

sudo ln -s /usr/lib/ /usr/lib/ruby/gems/1.8/gems/rmagick-2.6.0/lib/

A gem list shows the gem installed:

rmagick (2.6.0)

This now works, but is an ugly hack..

Rails setup

10 Sep

1. Get source code from repository
2. Install Ruby
3. Get RubyGems tarball from
4. Explode tarball, run “ruby setup.rb” – this will install gems
5. Install mongrel: “gem install mongrel”
6. To run mongrel: “mongrel_rails start”

Note if there are complaints about RMagick/ImageMagick:
(e.g.: “/usr/lib/ruby/gems/1.8/gems/rmagick-2.5.2/lib/ cannot open shared object file: No such file or directory – /usr/lib/ruby/gems/1.8/gems/rmagick-2.5.2/lib/ (LoadError)”)

  • Get the ImageMagick tarball
  • cd ImageMagick-xxx
  • ./configure
  • make
  • sudo make install
  • sudo gem install rmagick
  • export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
  • mongrel_rails start

Rails migration

14 Apr

To change the database:

ruby script/generate migration add_column

Useful Rails commands

22 Sep

Similar to print_r in PHP is the YAML::Debug(object)

e.g. if you have an object @foo

print YAML::dump(@foo)

remove an element from a hash:


Rails – Getting Started

5 Sep

Useful rails commands.

To get a basic rails page going:
1. Get rails up to date
$> gem update -y –include-dependencies

2. Get the generic rails stuff into this directory
$> rails stock

3. Create the model (i.e. the database)

a. Create the schema for a table called ‘Stock’ with the ‘name’, ‘code’, ‘price’ and ‘sector’ columns
$> ruby script/generate scaffold_resource Stock name:string code:string price:integer sector:string

b. edit config/database.yml to define your development db (you might wanna use sqlite), e.g.

  adapter: sqlite
  database: db/stock_development
  username: root

(Note i had to install sqlite and libsqlite-dev as well as do a ‘gem install sqlite’ to get this to work)

c. Execute the sql
$> rake db:migrate

4. Create routing
Edit config/routes.rb to map the table name and add the controller name.
(Note the controller name is the same as the name in app/controllers/stocks_controller.rb)

map.resources :stocks


map.connect '', :controller => "stocks",:action=>"index"

5. Start the server with WebRick the dev webserver
$> ruby script/server webrick

6. Go to the page with a webserver

Powered by ScribeFire.