Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Author Archives: Peter Cooper

By Peter Cooper / June 13, 2006

From the ever-productive Erik Veenstra comes AllInOneRuby, a “Just-in-Time and Temporary Installation of Ruby”. The concept is simple:

AllInOneRuby creates a compressed executable for Windows, Linux or Mac OS X (Darwin) that includes both the Ruby interpreter and the runtime libraries. Why? Because it’s sometimes not easy, or possible, or desirable, or allowed to do a complete Ruby installation. That’s where AllInOneRuby comes in. I always have a USB-memory stick with AllInOneRuby in my pocket.

I need to try this along with Platypus, and see if I can deliver a complete working Rails application as a ‘click and run’ application for regular users on OS X (and Windows, though not with Platypus). Read More

By Peter Cooper / June 13, 2006

Delynn Berry has developed a useful plugin called UserStamp. Whereas Rails has built in support for automatic columns such as created_at and updated_at, it doesn’t (quite rightly) support concepts such as created_by, as these belong in the application domain. It’s a commonly required feature though, and Delynn has done a great job of packaging it up.

This is also worth looking at if you want to get an idea of how to put a similar plugin together. Most Rails applications have similar requirements and packaging them up as plugins makes it a lot easier to manage. Read More

By Peter Cooper / June 13, 2006

Rideme2

Project RIDE-ME is a new, open source, IDE and development environment for Ruby on Rails (though it’ll work with just Ruby too, of course) on Microsoft Windows. Unlike most other Rails IDE attempts, it’s not based on Eclipse, and is designed to make life easy for coders migrating across from Visual Studio. It certainly looks nice, although the reports are that it currently lacks a debugger, Subversion support, and a few other things. Looks promising though, and I think this could become rapidly popular with those who aren’t keen on Eclipse.

It makes me think that if there were an IDE like this with a lot more features, the author could easily charge $50 for it, and it’d sell like hot cakes. Read More

By Peter Cooper / June 13, 2006

Menearailes

It makes me wish I could read Spanish, but MeneaRailes appears to be a clone of Digg, but focusing on Ruby on Rails articles (again, mostly in Spanish). It’s only a matter of time before someone makes an English version (I already tried, but I haven’t had the time to get it right, I’m afraid). So.. Spanish readers, enjoy! Read More

By Peter Cooper / June 12, 2006

A few days ago, Courtenay of Caboose posted an article called ‘pretty tables for ruby objects‘ that give a MySQL-command-line-client style textual view of data stored in your Rails database. The syntax worked like this:

puts Invoice.pretty_table(nil,{:max_width => 50, :line_spacer => ‘-’, :find => { :order => ‘created_at desc’ }})

For an output like so:

| created_at | updated_at | name | due_at | p |
—————————————————————————————————————
| Fri Jun 09 14:17:00 PDT 2006 | Fri Jun 09 18:34:55 PDT 2006 | Website | Sun Jul 09 14:17:00 PDT 2006 | 1 |
| Fri Jun 09 14:01:00 PDT 2006 | Fri Jun 09 18:34:55 PDT 2006 | May | Fri Jun 23 14:01:00 PDT 2006 | 1 |
| Sat Jun 03 12:25:00 PDT 2006 | Fri Jun 09 18:34:55 PDT 2006 | Invoice 3 | Mon Jul 03 12:25:00 PDT 2006 | 3 |

It didn’t make sense to me and I suggested developing a version that worked in this way instead:

Something.find(:all, :conditions => ‘whatever’).pretty_print

This way you can use your regular model accessors and simply use the ‘pretty’ output on any result set whatsoever. Read More

By Peter Cooper / June 12, 2006

BackgrounDRb, by Ezra Zygmuntowicz, is a system that lets you run long running tasks in the background, and not in the scope of your application. For example, you might have a Rails application that needs to send 100 e-mails, but rather than tie it to an HTTP request, you can simply pass off the job to a BackgrounDRb object and let the user know everything is proceeding as planned. There’s more information here.

It’s powerful stuff, and worth looking into if you have anything like mass mailing or other remote communications that isn’t request dependent, but still needs to be carried out. Read More

By Peter Cooper / June 12, 2006

Coda Hale is a Rails developer from Berkeley, CA, who’s developed a ton of useful plugins. I’ll leave the descriptions to Coda:

content_cache

Cache rendered views within the context of your layout, allowing you to mix dynamic content with cached static content.

dollars_and_cents

Stores prices as integers in your database, but access them as floats.

dynamic_session_exp

Allows you to configure Rails to serve up session cookies with expiration dates relative to the current time, instead of some fixed date in the future.

http_caching

Allows your Rails application to take advantage of the caching mechanisms built into HTTP 1.1 (i.e., 304 Not Modified return code). Read More

By Peter Cooper / June 12, 2006

Simplelog

SimpleLog is a ‘simple Ruby on Rails weblog application’ by Garrett Murray. It features tagging, search, multiple author support, pinging, provides an RSS feed, and it’s fast. It’s only one of several solutions available now, but the code is available for free, so there’s always something to learn :) Read More

By Peter Cooper / June 12, 2006

It’s not the nicest code you’ll ever see, but it’s a great demonstration of the power inherent in Ruby on Rails. Miklos Hollender demonstrates how he created a version of Web 2.0 app, Reddit, in under 20 minutes using Rails, scaffolding, and a little elbow grease. Source is included.

An interesting aside based off of this is an interesting video demonstrating how to recreate Reddit in Lisp in 20 minutes, as Lisp is somewhat a cultural uncle to Ruby, it’s worth watching. Read More

By Peter Cooper / June 11, 2006

Paul Lutus says:

I have always felt that a language hasn’t really arrived until there is a source beautifier utility for it.

So he developed one. It’ll take a pile of messy code, indent it, and make it look good. Enjoy! Read More

By Peter Cooper / June 11, 2006

Rubygame is a new library that provides ties between the SDL (Simple DirectMedia Layer) and Ruby, so that you can do graphics and sound work from Ruby, ultimately to build games. It’s stylized off of the popular pygame, the equivalent library for Python. Unfortunately it currently only works on Linux (and other Unix-like systems) but Windows and Mac users should be in luck soon.

If playing with OpenGL, 3D graphics, and building some simple games sounds appealing to you, Rubygame is the place to be. Read More

By Peter Cooper / June 11, 2006

One of the features of Rails 1.1 was the ability to automatically detect clients that could understand XML and send XML responses to them using the respond_to method. This also works for AJAX requests and HTML, of course. Unfortunately, though, this relies on XML and API clients sending the correct Accept headers in most cases, and, as we all know, users aren’t necessarily so smart (even API users!).

In response to this problem, Edge Rails now accepts the format parameter on the URL, like so: http://www.yourapp.com/post/show/1?format=xml So while the Accept header method still works, you can also pass in the format directly via the URL. Read More

By Peter Cooper / June 9, 2006

Steve Yegge explains how to use Ruby to script your Windows applications. His first example demonstrates how to load Internet Explorer, get it to navigate to a certain Web page, and scrape the content in just five lines of code, like so:

require ‘win32ole’
ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.navigate(“http://{internal-website}/your-desired-url”)
sleep 1 while ie.readyState() != 4
html = ie.document().documentElement.outerHTML
ie.quit()

Excellent! This makes me wonder if there’s a similar mechanism (not AppleScript) for OS X. Anyway, learn more, including more complex demonstrations, at Steve’s post. Read More

By Peter Cooper / June 9, 2006

The Charming Ruby Compiler is charming not just by name, but by nature. It’s a thesis project at the Computer Science Department at Chalmers University of Technology in Sweden to develop a proof of concept Ruby compiler that compiles to the C– intermediate language. So far, they’ve only got the basics working, but it’s an interesting project, if only to learn about C–, an interesting ‘portable assembly language’ that makes life easier for compiler developers. It seems a little like Parrot, and is funded by Microsoft Research and the National Science Foundation. Read More

By Peter Cooper / June 9, 2006

Rather than use the send_file or send_data methods to send an entire, completed bulk of information back to the client, David N. Welton wanted to, effectively, print stuff to the client bit by bit. He worked out how to do it and presents his findings and sample code here.

A preview of his ‘output data to CSV line by line’ method: Read More

def generate_file
@headers["Content-Type"] = "text/comma-separated-values;"
@headers["Content-Disposition"] = "filename=\"some.file.txt\";"

i = 0

render :text => Proc.new { |response, output|

output.write("some generated text…")

}, :layout => false
end