Archive for May, 2009

Set Cookie in HTML Body for Rails 2.3.2

Tuesday, May 26th, 2009

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
3
Tags: , ,
Posted in tech |

Swiff Uploader argumentsToXML Error

Wednesday, May 6th, 2009

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();
  		}

  	});
0
Tags: , ,
Posted in tech |

Upgrading from Rails 2.2.2 to Rails 2.3.2

Monday, May 4th, 2009

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.

3
Tags: , ,
Posted in tech |