Category Archives: ruby

GVM vs RVM

After not requiring Groovy for a while, I went about installing it today and was directed to GVM. Very interesting and quick to install. But essentially a RVM knockoff for java.

Rails / Ruby DateTime Stuff

A great blog entry: http://anandmuranal.wordpress.com/2007/12/12/formating-date-time-in-rails/

Rails update a gem to an older version

You want say rack version 1.0.1 but the latest version is rack 1.1 and it’s installed on your machine:

gem install [gem name] –version [version number]

For example:
gem install rack –version 1.0.1

Getting Threads in Rails

So you want threads in rails? Add the following 2 lines to your production.rb file:

config.threadsafe!
config.eager_load_paths << “#{RAILS_ROOT}/lib”

For more reading, checkout: http://m.onkey.org/2008/10/23/thread-safety-for-your-rails

Viewing RDoc for installed gems

Pretty simple:

gem server

It’s then available on localhost:8808

Pretty cool. It’s like having available doc for JAR files. Sort of.

Metaprogramming in Ruby is awesome

Well I had to override the behaviour of the Oracle Enhanced Adapter when creating sequence names. By default it creates them as “tablename_seq” where our database was “sq_tablename”.

After reading this post. I made my change and placed it under the config/initializers directory.

But the concept of metaprogramming in Ruby is really intriguing.

Excuting Rails Unit Tests without blowing away your database

Okay …

I have my nice shiny rails app. I have written a heap of tests. But I don’t want to blow the TEST database away each time I execute rake test:units.

Be aware when you use say “rake test” it calls “rake db:test:prepare” which essentially blows away your test database and reloads it.

There are a couple of approaches:

One: Run the test through Ruby and not Rake
——————————————-
Run your test: ruby -I test test/unit/my_test.rb

The -I flag ensures that the file /test/test_helper.rb is loaded.

You could then write your own rake task to run all the unit tests.

Two: Write your own rake task to use instead of rake test:units
—————————————————————
In this approach. The aim is to ensure that the “db:test:prepare” task is not called. You do this by clearing the prerequisites for “rake test:units”

i.e.
task :test_units do
Rake::Task[‘test:units’].prerequisites.clear
Rake::Task[‘test:units’].invoke
end

You then invoke your task: “rake test_units”
Also call “rake -T” to see your task listed.

For more details:
Check out Paul Barry’s post
Jay Field’s post

On the Rails Hype Cycle

I found this interesting graph on a blog entry about the Technology Hype Cycle.

The diagram is interesting and made me think about my current Rails experience. Each time I code and do something, I really enjoy myself. A side question is … am I allowed to enjoy myself whilst coding? Past experience in most Java frameworks has been defined more by pain than “enjoyment”. I digress.

Two days ago a new rails book I ordered from Amazon arrived(Simply Rails 2 – by Patrick Lenz). I was frothing with anticipation. Even though I have only read the first few chapters and I haven’t really learned anything that I didn’t already know, yet I am still frothing.

I think that I am still on the way to reach the peak of Inflated Expectations. I just hope that when the Trough of Disillusionment sets in that it won’t be so bad. I guess live it up now.

I am really enjoying Rails!

Well for a freelance project, I decided to use Ruby On Rails. I have heard the hype. Seen developers at work use it … blah etc.

After mixing tutorials for Rails 1.2 and Rails 2.0 (There are not that many for 2.0) I actually managed to code something quite easily. I was quite surprised. I think that the scaffolding thing is just awesome. I even “rewrote” my small app a few times as I learnt to do it better. I think the telling thing was that I wrote the app in Rails 2.1.0. Once I uploaded it to my server I was having it hosted on, I realised that they only offered Rails 2.0.2. I rewrote it again. I even managed to figure out how to various rails versions on my local machine and use the version I wanted. Very cool.

Some helpful Rails 2.0 tutorials:

I did this all on my mac. I installed Mamp to get MySql and I eventually settled on textmate as editor as my machine just did not have enough grunt to use Eclipse.

The really great thing is that I am enjoying it. There are some things that have been frustrating, but this has been way easier to learn than say Spring/Hibernate combo.

Learning Ruby on Rails 2.0

I have finally made some time to start learning Ruby on Rails. Here’s my story:

Downloading and installing
Well at home I am running windows on a laptop with busted keys. Because one of my offspring keeps ripping keys from the keyboard. The latest victims are the spacebar and the “n” key. Sad but true. So I am a little lazy at times I so installed instant rails: http://instantrails.rubyforge.org/wiki/wiki.pl

Finding a suitable tutorial
I then discovered that there is a difference between Rails 2.0 and 1.x. But Rails 2.0 tutorials seem hard to come by (well again if Google does not produce on the first page … then it’s hard to find 🙂

Ones that I did find and am working through:

Will update as I go.