Rails Hosting Comments: Dreamhost

I had an email the other day asking about my experiences with a particular shared hosting company (not dreamhost). I’ve worked my way through a few companies for smaller projects, and thought I’d throw some thoughts out there. Dreamhost are one of the cheaper hosting outfits around, and seem to inspire either love or hate, depending on your experiences. Their setup for rails is apache+fcgi, which isn’t the optimal configuration, but works well enough for a low-demand application or one where a lot of content can be cached. ...

OpenID for a Ruby on Rails app

The buzz about OpenID keeps building, and with the announcement that all AOL/AIM users now automatically have OpenIDs it doesn’t look set to slow down any time soon. For those who’re not familiar with the concept, OpenID is a distributed single sign-on system that lets you set up one account and then log in to any OpenID compliant site using that account. For a better introduction, check out this screencast from Simon Willison. ...

Intercepting microformats in rails input

In Input formats and content types in Rails 1.2 I mentioned a project I’ve been working on that will provide a RESTful service interface which accepts its input in a number of formats, including microformatted HTML. For certain types of data microformats provide a great way to receive input as they don’t require your clients to learn a new schema to send you data. They can take the same semantically rich HTML they’re displaying on their website and POST it to your endpoint. Or they can use a tool like Ryan King’s hcalendar creator to generate some sample input. ...

model_auto_completer

Rails’ auto_complete integration is pretty nice for building search functionality, but for entry forms it all too often falls short. Typically if I’m using an auto complete field in a form it’s because I want to link that record with an existing entry in another table, such as connecting an event with a location, or a book with a publisher, and that won’t work because the value obtained from the auto completion is the name of the linked entity, not its ID. I’ve tried various ways of managing that, either by overriding the standard methods or by adding some extra code in my model that will convert a name back into the associated model ID, but they all feel like hacks and I’d not had time to clean up the code and package anything as a plugin. ...

Edge Rails Saves You Money (and improves performance)

For anyone who serves up content that is requested repeatedly by the same user agents (be they web browsers, news readers, or any other) it can quickly get expensive (financially and in performance hits) to use up bandwidth sending the same data to the same destination over and over. HTTP provides mechanisms to deal with that, but until recently they’ve been poorly supported. Those costs are the reason that this is great news. DHH just committed a change to Edge Rails that automatically adds an ETag when sending a response and returns an HTTP 304 (Not Modified) when an agent comes back asking for the same content before it has changed. ...

Speeding up Rails with erubis

However much we buy into the adage that hardware is cheaper than developers, we all still need to make our code as responsive as possible. We tune the database, we refactor our code, and try to find the optimum balance between developer time, code legibility, and performance. In the process, many of us have found that rails’ rendering, particularly the Erb library is one of its slowest parts. Enter Erubis. ...

Extending acts_as_locateable

There have been quite a few geographically-themed Rails plugins emerging over the past few months and I decided it was time to try out acts_as_locateable. Acts_as_locateable is based on ZipCodeSearch. It loads in a database mapping US zip codes to coordinates and then adds convenience methods to ActiveRecord objects that let you search by distance. eg. Event.find_within_radius(50, '49503') will return all events within 50 miles of me. What the standard plugin doesn’t allow is the passing in of more search parameters. So if I wanted to limit that search to future events I’d have to retrieve all the results and iterate over them. In a large system that could be very inefficient. ...

Input formats and content types in Rails 1.2

One feature of recent releases of Rails I hadn’t spotted before is the ability to define your own parameter parsing based on content type. I’m working on an application that will employ a RESTful API and that I hope will take its input in either standard http parameters, microformatted HTML, XML or JSON. I don’t really want to have to write custom code within the controllers to interpret the input based on content type, so I started looking for how rails parses XML input and came across the following in the actionpack changelog: ...

GOOD Magazine

Yesterday we pushed the button and launched the new version of GOOD Magazine, a site I’ve been working on for the past couple of months along with the folks at Area17. It’s a relatively large Ruby on Rails system built on top of the ORGware system (refitted as an engine) and supported with a caching system built for Madame Figaro. Most of my work has been under the hood, but where I’ve touched the frontend I’ve tried to make use of microformats and other good practices. We’re providing a range of atom feeds (which will become easier to find over time as we make some refinements) but eventually I hope that we’ll have all listing pages using hAtom so that anything can be a feed. ...

Syntax highlighting without breaking HTML

Ruby on Rails provides the very nice helper method highlight to identify search terms within a string. We’ve been using it quite a bit on a large project but recently began to notice that it broke the HTML in certain places. It turned out that our problem was that our search term was showing up within an attribute on a tag, and so highlight, oblivious to the content of the text it was parsing, was inserting tags in the middle of attributes, and all kinds of craziness was ensuing that just wouldn’t do. ...