Gravatar

Geoff Evason

Set Cookie in HTML Body for Rails 2.3.2

I recently upgraded an app to rails 2.3 and on many pages on my local machine the top of the HTML body included something like this:


Set-Cookie: _myapp_session_id=BAh7B...; path=/; HttpOnly

I couldn’t figure out what was happening until I found this forum post which explained that the problem was related to passenger 2.0.6. To fix the problem I just needed to update the version of passenger I was running.

To update passenger (on a mac) was pretty simple. Just run the following 2 commands:


sudo gem install passenger
sudo passenger-install-apache2-module

Depending on how you set up your local apache instance, you may also need to update the config. I needed to update /etc/apache2/httpd.conf to


LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.1.2

Swiff Uploader argumentsToXML Error

I was working on getting the Swiff uploader working with a wedding vendors application and was getting the following javascript error:


__flash__argumentsToXML is not defined

After banging my head for a while (the exact same code was working fine on another website) I discovered the problem. It was a really silly oversight on my part. I didn’t have the file Swiff.Uploader.swf in the right location!!!

Make sure that when create a swiffy object you have a the above swiff file where you set it in the path:


    $('upload-fallback').removeClass('hide');
  	var swiffy = new Fancyuploader2($('upload-status'), $('upload-list'), {
  	...
        /* This is the important bit re: this blog post */
  		'path': '/swf/Swiff.Uploader.swf',
  	...
  		'target': 'upload-browse-images', /* This is for flash 10 */
  		'onLoad': function() {
  			$('upload-status').removeClass('hide');
  			$('upload-fallback').destroy();
  		}

  	});

Upgrading from Rails 2.2.2 to Rails 2.3.2

I recently upgraded one of my apps from Rails 2.2.2 to Rails 2.3.2. It was actually a really easy upgrade, but there were few little gotchas I had to watch out for, so I thought I’d share my experience.

Upgrading Rails

I imagine there is probably a better way to do this, but since I change the version of rails so infrequently I’m not sure. (If there is a better way, please let me know). My flow is as follows:

Install the new version of the rails gems:


sudo gem install rails

Branch your app


git branch newrails
git co newrails

Remove the old version of frozen gems


git rm -rf vendor/rails

Update your config/environment.rb file to the new version of rails:


RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION

freeze the new gems


rake rails:freeze:gems

Please note, that if instead of installing the new gems and freezing them from your local gems, it looks as though you need to be careful if using rake rails:freeze:gems. You can read more about it in the official post or in this post which I found more understandable.

Testing Your App

The first and most obvious error you will run into is this:


uninitialized constant ApplicationController

This is because as of Rails 2.3 application.rb is now application_controller.rb. To fix this just do


git mv app/controllers/application.rb app/controllers/application_controller.rb

The next error I got was


undefined method `relative_url_root' for #

I narrowed this down to a stylesheet_link_tag call. I got around this by updating the asset_packager plugin, and updating HAML to 2.0.9. By the way, if you’re not using asset packager, you should be.

That’s it! It overall was a very easy upgrade that took much less time to test than my rails 2.1 to rails 2.2.2 upgrade.

Here are some other rails 2.3 gotchas to watch out for courtesy of thoughtbot.

Dear Yahoo – Please get with the program (or, why am I still getting traffic to my old IP even though I updated my DNS entires?)

Recently we move our wedding website application to ec2 servers.  Part of doing so meant updating DNS entries.  5 days after changing them, I’m still seeing traffic to the old servers… :-(

Part of moving to ec2 required us to move to a 3rd party DNS solution.  We chose DynDNS.  Their offering is pretty good, but I’m less then impressed with their support.  [their response time is about 24 hours and when I asked why I'd still be getting traffic to the old IP and what I might do about it they basically said "that's not our problem"...]

Anyway – before changing hosts I set the DNS TTL to 20s. I was surprised to see traffic to the old IP a day later. On the second day I got worried. After a few more days I was even more so…

After looking through the logs a bit more it seems that almost all of the traffic in the last two days is coming from the IP 72.30.79.108 – which turns out to be one of yahoo’s crawlers…

So, Yahoo, if you read this, please make sure your crawlers respect DNS records… Otherwise you’re getting stale data…

Setting a Capistrano Variable from the Command Line

It took me a little while to find a solution for this, so I thought I’d post it.

I was cleaning some deployment dirs and wanted, just for this instance, to only leave 1 release as opposed to the 5 releases that capistrano leaves by default. Keep in mind this was across about 6 apps and 2 stages for each.

Option 1: Add the following to the deploy.rb files:


set :keep_releases, 1

That would require changing them all back afterwards.

Options 2: Set the capistrano variable from the command line:


cap deploy:cleanup -s keep_releases=1

Northern Beaches Toastmasters

Domain Name Registration API Plugin for Rails

If you’ve ever had an app where you want to allow users to purchase a domain name, you’ve probably felt the pain of trying to interface to a registrar.  Although some have APIs, my search found that most were hard to interface to or poorly documented.  Many even required signing up as a partner (and paying a big fee) before you could even get documenation.

After much searching and experimenting I decided to go with Register.com’s XML api for my app. They offered the best API, and the easiest signup path.

I bundled the main part of the interface into a rails plugin.  The plugin is stored on github: http://github.com/geoffevason/register-api/tree/master

To install the plugin do this:


script/plugin install git://github.com/geoffevason/register-api.git

The plugin is of little value unless you have spoken to register.com and have received their API documentation. You need to register as a partner (it’s free) and have the IP of your dev machine whitelisted for testing.

Most of the info on use is in the readme in the plugin. You can call any of the Register.com API methods by calling Register::API.


# A call to the API looks like this
# Register::Api::Call(params)

# Example to check if the domain name google.com is available
Register::Api::Check( :tld => 'com', :sld => 'google' )

The plugin also contains a few helper methods and classes. If all you want to do is let people search for an available domain, and purchase it, then everything you need is in these helpers. Some important logic remains in my controllers, but if you have any questions, let me know. geoff [a] evason.name

New Developments For The Wedding Website Business

There have been a bunch of developments with MomentVille recently that I’m pretty stoked about.

First, we have created a partnership with Modern Girl Invitations so that we can provide some designer wedding website themes that have matching modern wedding invitations.  :-)

Second, we’ve written guest blog post: why you should make a wedding website.

Third, we now let users purchase their own domain names! During testing I bought some neat domain names, such as www.websites-wedding.com

Finally – our legendary CTO Paul is working on a wicked-cool new way of using music on the site.

Fox News : War Games

I came across this article on digg. Its about a Glenn Beck program on Fox News called ‘War Room’. The article provides an interesting read (though a bit long). The embedded fox videos contain a fair bit of fear mongering, a la… <The government isn’t upholding the values of the constitution and the militias (or bubbas) may need to fight a new civilwar in 2104>

The videos will mean different things to different people based on their views. The reason I’m writing THIS post is to point out a glaring error in Fox News’ fact checking.

War Room Scenario #2 paints the very bleak outlook :

50 million people worldwide are unemployed. There are riots in the streets.

The problem is, as of 2007 there were 180 million people unemployed!

Just image the carnage that would be unleashed if 130 million people got new jobs!

Safari : The Cookie Monster

safari cookie monster

Safari has been causing me much grief recently.  It would seem that I’m not the only one, and so far I’ve been unable to find any suggestions other than deleting all your cookies and and resetting Safari (a solution which doesn’t actually work) .

I seem to constantly get logged out of various web apps when using Safari, including Facebook & Gmail.  With Gmail I usually get an 400 error message or a warning the the header is too long. Sorry to anyone who was hoping to read a solution here. I don’t think anyone has one at the moment.  I really just wanted to post the image and vent a little…