Back to Main - Articles tagged with the "Code" category:

Open Source Ruby Library for the Merlin API

Along with the previous post, I would like to announce the ruby-merlin library.

If you are working with Merlin API data inside a Ruby or Rails application, be sure to try the library.

Open Source Ruby Library for the IDology API

While working on a recent project, I wrote a Ruby library for interfacing with the IDology API.

If you are building a Ruby or Rails application and need to work with IDology data, have a look at the ruby-idology library.

DeRailed ActiveResource Presentation

I'm getting ready to present at the Denver Rails user group (DeRailed) this evening on the topic of ActiveResource.

No doubt half the people in the audience are spacing out and dreaming about the iPhone release tomorrow...

Here are the slides.

Mime Type CSV Bug in Rails 1.2.2

Does this warning look familiar?

"mime_type.rb:48: warning: already initialized constant CSV"

Here's why. CSV was added as a pre-defined mime type to Rails 1.2, but a very minor bug causes the mime type to not be available for use. So you have to define it yourself using the code below (usually in environment.rb):

Mime::Type.register 'text/csv', :csv, %w('text/comma-separated-values')

This code then causes the above warning to appear.

I did some digging and found the error in mime_type.rb. I considered submitting a ticket / patch, but right now the Rails Trac is down and I can't do much with it. I was able to look at the trunk source and see that mime_type.rb has been re-written, so this problem will go away in future versions of Rails (or if you are using Edge Rails).

Here's a quick fix that I am using in one of my production application's (which is frozen to Rails 1.2.2) environment.rb -

Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)

The above line will fix the issue for Rails 1.2.2, and will be ignored if the specific bug is ever fixed in the current structure of mime_type.rb.

Missing Gems = Strange Rails Errors

I was working on a project for a client yesterday and kept getting a strange error message when I tried to run the unit tests.

I would type in "rake test:units" at the prompt and get the following:

test_helper.rb:18: undefined method `use_transactional_fixtures=' for Test::Unit::TestCase:Class (NoMethodError)

What? How could "use_transactional_fixtures" be undefined? I kept poking around and finally discovered I was missing a Ruby gem required by the project. Strange how it would generate the above error...

Bottom line, make sure you have all of your required gems installed and updated!

AWStats single IP issues with LightTPD / Apache proxy

While setting up AWStats for ProjectStat.us on TextDrive, I ran into a problem. Every incoming request to ProjectStat.us is proxied through Apache to LightTPD. No problems to this point. But when it came time to run a stats program like AWStats on the log files, a problem appeared - every request has the same IP - Apache's.

After some quick searching, I came across James' hint. I was able to add the following line to my lighttpd.conf file and now all incoming requests have their unique IP logged.

accesslog.format = "%{X-Forwarded-For}i %v %u %t \"%r\" %>s %b \"%{User-Agent}i\" \"%{Referer}i\""

Switchtower with TextDrive

Switchtower is awesome, but can be a pain to configure on shared hosting services like TextDrive.

Installation on my dev machine was easy, but when it came time to run "rake deploy" I kept getting remote server errors.

I spent 30 minutes tracking down the problem. For TextDrive (and I assume other shared hosts), make sure you have the following line in your config/deploy.rb file:

set :restart_via, :run

The reason is that Switchtower defaults to using "sudo" to run certain commands, which is not possible on a shared hosting service.

Pragmatic Studio Rails Alumni
RailsConf 2006
Pragmatic Studio Advanced Rails Alumni