home icon contact icon rss icon

Textmode

tools I use

Finally: Passenger/mod_rails for Nginx!

I was really glad to finally read the news that Passenger 2.2.0 now supports my favorite webserver nginx too.

I always wanted to get rid of the somehow apache monster, which is an overkill in some scenarios (imho).

Nginx has a very easy configuration and everything I need.

If you want to test passenger with nginx it’s as simple as:


sudo gem install passenger
sudo passenger-install-nginx-module

# edit the default config:
sudo vi /opt/nginx/conf/nginx.conf

# start nginx
sudo /opt/nginx/sbin/nginx

There is also a Peepcode Screencast explaining the steps.

I’m happy :)

Ruby 1.9.1 and Rails fails - at least according to Google..

Google seems to know something about the new Ruby 1.9.1 release regarding Ruby on Rails:

The question is, does Google suggest “fails” as a correction for “rails” because the word is similar – or because the combination is typed in a lot? :)

Rails and Merb unite

If you did not already read it, there are really cool christmas news on the Ruby on Rails Blog

The Merb Framework – the highly modified framework initially based on/inspired by the rails core and made to improve speed, concurrency and a small footprint – will be merged into “Rails 3.0”.

Let’s look at the Merb feature list to see what this means:

Merb is..

  • ORM-agnostic (through plugins)
  • JavaScript library agnostic (through plugins)
  • template language agnostic (through plugins)
  • thread safe (+ multiple file uploads)
  • simple and optimized core without sacrificing functionality
  • improvements

what I especially like is the modularity of Merb, compared to Rails

This is a rough overview of what Rails 3.0 will look like, having the Merb features:

  • Optionally a minimum and full featured core
  • A lot of performance improvements
  • Framework agnosticism (JS, ORM, template and testing level)
  • A better, more stable API (eg. for plugins)

When will we get Rails 3.0?

I guess this is very hard to predict :) but the goal is to have at least a Beta version ready for RailsConf 2009 in Las Vegas

I totally concur with the post on the ROR Weblog, Rails 3.0 will kick ass!

Official Ruby on Rails Security Guide

Finally there is an official (?) Ruby on Rails Security Guide available, on rubyonrails.org

It seems to be pretty up-to-date and covers a variety of current issues quite detailed.

I consider this a must read for everyone, especially when developing public applications. There is an online version as well as a free e-book available.

There are even more Guides available at guides.rubyonrails.org

Braid: Simple vendor git/svn vendor branch tracking

I came across a new gem to simplify vendor branch management in a Ruby/Rails Project under GIT: Braid

Braid helps you to manage GIT and SVN vendor branches, a simple example for rails:


# add rails:
braid add git://github.com/rails/rails.git vendor/rails

# add some plugins:
braid add git://github.com/tablatom/hobo.git -p
braid add  git://github.com/dchelimsky/rspec.git -p
braid add git://github.com/thoughtbot/factory_girl.git -p

# updating rails
braid update vendor/rails


Braid also supports:

  • revisions
  • full (History) or squashed mirrors
  • diff information
  • locking/unlocking of mirrors

Looks like it could really save some time – especially when working with both, Git and SVN.

Give it a try: Braid

Ruby Refactoring Book

Some time ago I wrote about a pretty good refactoring book, and complained that there are no Ruby related refactoring books or tools.

Well, time changes, and here it is: Refactoring: Ruby Edition. It’s available for pre-order, go get it :)

Factory Girl - Rails fixture replacement

I think you all know that, when using fixtures in your test, you keep switching between files to see what fixtures there are, always struggling with dependencies and conflicts.

There are a couple of helpers that solve this, but this is the best one I came across until know: Factory Girl

As the names says, it provides some kind of factory for your objects and instances.

The following snippet illustrates the definition of such a factory:


# define an incremental username
Factory.sequence :user do |n|
  "user#{n}" 
end

# define a user factory
Factory.define :user do |u|
  u.admin      false
  u.username { Factory.next(:user) } # lazy loaded
end

# define a project factory with associated user
Factory.define :project do |p|
  p.title 'myproject'
  p.creator   {|a| a.association(:user) } # again lazy loaded
end

Now, this factory can be used in your tests:


it "should do something" do
  Factory.create(:user) # creates a user
  Factory(:user) # creates another user (note the shortcut)
  @u = Factory.build(:user, :username => 'customuser') # only build, no save
  Factory.create (:project, :creator => @u)
end

I think you get the basic idea behind it, it’s actually pretty clean and makes tests a lot more readable without looking at fixtures.

Note: At the time of this writing, the attribute name does not work since there is a conflict (that will be resolved soon). Instead you have to use:


Factory.define :project do |p|
  p.add_attribute :name, "myname" 
end

21 nice Ruby tricks

Although there are tons of tricks and shortcut sites, 21 Ruby Tricks You Should Be Using In Your Own Code by Peter Cooper is really nice.

Many things I did not really use or forgot. Check it out.

ClusterSSH, SSH to multiple servers (Rails Deployment)

If you have a cluster of similar machines, for example Ruby on Rails deployment hosts, you often need to run the same configuration or monitoring tasks on all of them.

Much like capistrano, ClusterSSH provides you a way to execute commands in multiple hosts at once.

The setup of ClusterSSH is very easy, just install it and run:


sudo cssh -u > /etc/csshrc

This will generate the basic, system-wide configuration file, which let’s you configure a lot of options.

Now, to add your hosts I created the file ~/.csshrc in my Home directory, containing for example:


host1 = example1.com:2300
host2 = example2.com
hosts3 = example3.com user@example4.com
group1 = host1 host2
all = host1 host2 hosts3

I think thats pretty straight forward.

Now if you type in cssh group1 at your command prompt, you will get one main control terminal to issue commands, which are then executed in the additional server terminals.

Heroku - Instant, live Rails Applications

I tested Heroku today. Heroku is a project for online development and hosting of Ruby on Rails applications. All configuration, development and settings are controlled with a nice web interface.

The application is live and accessible right after you created it.

Easy Configuration

In the basic settings you can customize the name of the subdomain, as well as the visibility of your project (public or private).

Import/Export Features

One cool feature is that Heroku lets you import existing rails applications, simply by uploading a tarball, and of course, exporting is supported too.

For Backup purposes you can even create multiple Snapshots of your current project which are then stored serverside.

Collaboration

It is possible to add multiple collaborators to projects through their email addresses, this can be very handy as a quick development platform for small groups, training, presentations or discussion.

Online Development

The Edit Mode of your applications offers a nice interface divided into 3 sections:

  • Code View, has a fully functional, web-based editor that lets you edit the project files as well as basic filemanagement tasks and access to Generators, Rake tasks and even the Console.
  • Data view, provides an interface to the project database
  • Log view, well the logfiles :)

Although I think I won’t develop full applications in Heroku, I think it is very handy for a couple of tasks:

  • upload and share existing applications very quickly
  • present or discuss applications online (eg. for training purposes)
  • work with various people through a nice web interface

Heroku is definitely worth a try, check it out.