Ruby Banter #010

Thijs van der Vossen, 29 Apr 2008, 20:47 in ruby on rails and video (edit).

In this episode, Eloy shows how to set up a class with default attributes in a single line of code.

Manfred and Eloy

3 comments

Testing multiple calls to an object

Manfred Stienstra, 29 Apr 2008, 12:14 in testing (edit).

Have you ever wanted to test multiple writes to $stderr? Mocking frameworks aren’t good at that, instead you can write a simple class to record method calls.

class Receptor
  require 'singleton'
  include Singleton
  
  attr_accessor :messages
  
  def initialize
    @messages = []
  end
  
  def method_missing(*attrs)
    self.messages << attrs
  end
end

$stderr = Receptor.instance

And in your tests:

messages = Receptor.instance.messages
assert messages.include?(['puts', "[!] Error!"])
assert messages.include?(['puts', "[?] Couldn't find preferences file."])

1 comment

Ruby Banter #009

Thijs van der Vossen, 21 Apr 2008, 11:08 in ruby on rails and video (edit).

In Smalltalk code and data are always kept together. In Ruby this isn’t the case. In this episode, Manfred looks at a poor man’s version of keeping your data with your code.

Manfred and Eloy

8 comments

Passenger on 64-bit Mac OS X

Manfred Stienstra, 18 Apr 2008, 12:10 (edit).

After some searching we found out that Passenger doesn’t run on Mac OS X because it segfaults on 64-bit BSD systems. All Core 2 Duo and Xeon systems are 64-bit, so that includes newer Mac Mini, Macbook, Macbook Pro, Macbook Air and Mac Pro.

A workaround for now is running Apache in 32-bit. Because Apache is compiled as a Universal binary, that is really easy to do.

The quick but short term solution is to start httpd by hand:

$ sudo arch -i386 /usr/sbin/httpd

The lasting solution is to change the Apache plist:

First we create a backup of the current plist.

$ sudo cp /System/Library/LaunchDaemons/org.apache.httpd.plist \
/System/Library/LaunchDaemons/org.apache.httpd.plist.bak

After that we open the plist in our favorite text editor.

$ mate /System/Library/LaunchDaemons/org.apache.httpd.plist

And change:

<key>ProgramArguments</key>
<array>
	<string>/usr/sbin/httpd</string>
	<string>-D</string>
	<string>FOREGROUND</string>
</array>

Into:

<key>ProgramArguments</key>
<array>
	<string>arch</string>
	<string>-i386</string>
	<string>/usr/sbin/httpd</string>
	<string>-D</string>
	<string>FOREGROUND</string>
</array>

And restart Apache:

$ sudo launchctl stop org.apache.httpd

Launchd will automatically start Apache for you after the stop command. Now Apache is running in 32-bit and should run Passenger just fine.

Update: Fixed in 1.0.2. Please update your gem and assenger-install-apache2-module if you’re having this problem.

No comments yet

Using Passenger on OSX for Rails development

Manfred Stienstra, 16 Apr 2008, 15:08 in ruby on rails (edit).

Lately a few things have been bugging me about Rails development using script/server. First, I can’t test through SSL and for applications who switch between SSL and non-SSL you really want your development environment too look as much like production as possible. And secondly, I have to manually manage my app server with script/server. This is a bit of a pain because some of our applications use ActiveResource to communicate so I need to start several app processes.

Proxying trough Apache solved the SSL problem, but now I had to remember on which ports I had to start my app server.

The solution turned out to be Passenger. First we install the passenger gem and compile mod_passenger.so.

$ gem install passenger
$ passenger-install-apache2-module

After that we turn on Apache at System PreferencesSharingWeb Sharing and edit the webserver configuration. I added everything to /etc/apache2/users/manfred.conf but Apache doesn’t really care where you put it, just remember to load mod_passenger.so before using Passenger specific configuration options.

Set up the Passenger configuration as explained at the end of the install script.

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Make sure our apps run in development mode.

RailsEnv development

Allow Apache serve files from our development directories.

<Directory "/Users/manfred/Code">
    Order allow,deny
    Allow from all
</Directory>

Finally, configure virtual hosts for our various projects.

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "/Users/manfred/Code/project1/public"
ServerName project1.local
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/manfred/Code/project2/public"
ServerName project2.local
</VirtualHost>

7 comments

May 6th: Rails ‘Morning coffee’ meeting in Amsterdam

Thijs van der Vossen, 15 Apr 2008, 10:40 in ruby on rails and meetings (edit).

It’s time for another ‘Morning coffee’ meeting. You’re invited to come chat with your fellow web developers over a nice cup of coffee.

When: Tuesday, May 6th, 2008, 9:30 AM

Where: The Coffee Company on the corner of the Nieuwe Doelenstraat and the Kloveniersburgwal in Amsterdam.

Please leave a comment if you’re coming, any questions you might have are welcome too.

7 comments

Welcoming Eloy Duran

Thijs van der Vossen, 14 Apr 2008, 11:47 in ruby on rails and business (edit).

We’ve been working with Eloy ever since he impressed us with his RubyCocoa demo at the 2007 RubyEnRails conference, and we are very happy that he recently decided to join the Fingertips team. He is not only a great developer but also a very nice guy. It is a joy to have him on board.

Eloy has been a Ruby developer for over four years. He is an active member of the RubyCocoa community where he started the Rucola project, a project that allows you to write RubyCocoa apps without XCode. He lives in Amsterdam on a boat together with his wife Dionne and their two cats.

2 comments

Fast and easy Rails hosting with Phusion Passenger

Thijs van der Vossen, 09 Apr 2008, 23:43 in ruby on rails and launches (edit).

Today Ninh Bui and Hongli Lai from Phusion visited the Fingertips office to introduce us to their Passenger Apache module for Rails. We’re very impressed with their work; installation and deployment is fast and easy and everything just works out of the box.

These guys did a really important job by completely removing the deployment hassle that has always been associated with Rails. They’ve made Rails deployment boring.

We’ll be testing Passenger on a server that’s running 15 small to medium Rails apps. You can expect an in-depth article about our experiences when Passenger will be released ‘any day now, honestly’.

If you’re interested in using Passenger in a bigger environment (for example, if you’re a shared hosting provider who wants to offer Rails support), you should get in touch with these guys to talk about the professional services they provide. Not only because they’re smart, but also because they’re a lot of fun to chat with. We really enjoyed their company.

1 comment