Developer blog

Mocra RSS feed

Packaging TextMate bundles in OS X DMGs

Last week Engine Yard released a CLI for their Engine Yard AppCloud. Delights such as:

Engine Yard.tmbundle

They simultaneously released a TextMate bundle to deploy, rebuild, view logs, etc using Ctrl+Alt+Cmd+E. Like all TextMate bundles, you can install it in one of two ways: via git (see the README), or via a beautiful DMG. Download it here!

Yes indeed, TextMate bundles can now be packaged up and distributed via DMGs using ChocTop!

Ruby on Rails.tmbundle

Read the full article on Dr Nic Williams's blog


Hudson CI server running cucumber in headless mode Xvfb

I was determined to get our CI server running cucumber features in headless mode. I ran into a few webdriver problems which resulting in a small monkey patch (capybara patch being written and submitted) for capybara.

This is how I got it running on a fedora 12 server (and some tips on getting it working on an ubuntu server).

On fedora

on ubuntu

To run Xvfb, in console simply type, then set a environment variable to bind all X requests from the command line to go to the new virtual deskspace

This will launch a new virtual display bound to display 99.

This is very cool. You can actually set up a vnc server and bind it to the virtual display to see what is happening!!!

On Fedora

On ubuntu

Simple run the following command! And point your VNC client to the installation server!

Test it by going to the command line and typing something like xterm or firefox!

Install the hudson gem

The hudson gem is in the gems repo, but for docmentation go http://github.com/cowboyd/hudson.rb

Read the full article on Mark Gandolfo's blog


Observers in Rails

In an effort to reduce the clutter of before and after callbacks in your Rails models an Observer can be used. In a simple use case, you may want to give the user 500 credits in your online store when they signup.

Without an observer your User model would look something similar to

Which is fine, if thats all that is in your model. But once your model starts to grow its generally a good idea to keep the callbacks in a different location! Observers to the rescue! With a Rails Observer your code would look similar to

Now tell Rails that you want your observer to be included

Rails will automatically understand that this observer is for the user class based on the name (convention over configuration to the rescue). Although you can also have an observer where the model can't be inferred by the name, in this case you can explicitly define the models the observer should be observing.

Read the full article on Mark Gandolfo's blog


How to debug rails apps

Coming from PHP I used to rely heavily on the die() command to print out debugging information. In rails nobody could really tell me if there was an equivalent, I was told to "raise", which I'm sure everyone feels is a bit dirty to use.

So I thought I'd quickly put up a few ways I debug in Rails.

Its a sexy little gem that lets you easily step through your code and even drop into an IRB session. To use it, make sure you have the gem or plugin installed and then.

Ruby debug shines when running a script/server (mongrel, webrick, etc) but can also be used with passenger, but with limitations.

This is equivelent to the PHP die() command. It takes an argument, evals and prints the statement to the screen. Note that it does halt execution.

This is a nice hacky way to print something out to the screen very fast, no matter where you are in your application.

Debug lets you easily eval something to a screen in your views.

Now that you have a bunch of debugging commands with rails, please stop using raise() to debug!

Read the full article on Mark Gandolfo's blog


Send Keys Released!

Send keys is a capybara extension that lets you send keystrokes to an element in the browser. It uses webdriver so must be used using the @javascript tag in your features.

Check it out at http://github.com/markgandolfo/send-keys and read about it at http://markgandolfo.com/pages/send-keys

First make sure you use the @javascript tag, to force capybara to use the webdriver driver.

Then in your features you can send characters or modifier keys to an element, or an array of modifier keys and keys. You'll need to use the css selectors to select an element.

For Example

Read the full article on Mark Gandolfo's blog


Want more to read?

The blog above is a collection of Mocra's thoughts, aggregated from Dr Nic Williams, Bodaniel Jeanes, Mark Gandolfo, and Jack Chen. Check out their individual blogs for more Ruby and Rails articles.

We also run the Ruby Done Right twitter account, full of great Ruby and Rails hints, tips and news.

    Loading...