Archive for the ‘tech’ Category

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 |

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?)

Monday, April 6th, 2009

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…

0
Tags: ,
Posted in tech |

Setting a Capistrano Variable from the Command Line

Friday, March 27th, 2009

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

Domain Name Registration API Plugin for Rails

Thursday, February 26th, 2009

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

2
Tags: , , ,
Posted in tech |

Safari : The Cookie Monster

Friday, January 30th, 2009
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…

 

 

0
Posted in tech |

Upgrading an app from Rails 2.1 to Rails 2.2.2

Thursday, January 15th, 2009

Here is a summary of a few of the problems I encountered while trying to upgrade an app from rails 2.1 to rails 2.2.2

Getting my dev code to run

First, to update the rails code:

 > rake rails:freeze:gems

The first time I tried to run the app I got this error:

vendor/rails/activesupport/lib/active_support/dependencies.rb:445:in `load_missing_constant': uninitialized constant Inflector (NameError)
Accessing the inflector changes, so as described here you need update APP/config/initializers/inflector.rb so it looks like this:
ActiveSupport::Inflector.inflections do |inflect|
  ...
end

In my case, I was also using the ActiveMerchant plugin which needed updating for the same reason

script/plugin install git://github.com/Shopify/active_merchant.git --force

According to gusg.us, HAML needs to be at 2.0.4.   I didn’t see any problems in my testing but I didn’t want to try my luck so I updated HAML too.

sudo gem update haml

update my environment.rb gem requirement

config.gem "haml", :version => "2.0.6"
Then run
rake gems:unpack:dependencies

Production

While deploying to a staging server I got this error:

initializer.rb:514:in `send': undefined method `cache_template_loading=' for ActionView::Base:Class (NoMethodError)

As described here, to fix this, just update your APP/config/environments/production.rb (and staging.rb) file by removing the following:

config.action_view.cache_template_loading

Overall, it wasn’t too painful an upgrade…

I didn’t run rake rails:update. That may have fixed some of these things on it’s own, but my understanding was that that wasn’t needed anymore…

7
Tags: ,
Posted in tech |