Subscribe to RSS Feed

Posts Tagged ‘ rubygem ’

I’m almost through ironing out the glitches caused by upgrading a rails 2.0.2 application to 2.2.2. Between the snippets of documentation scattered all over the web, I’ve muddled through a process that has taken a couple of days and been one of the trickiest framework upgrades I’ve had to make. For a long time, Rails kept me under the illusion that things were as easy as ‘rake makeeverythingwork’, but I think its true to say that the further I am into a rails project the less helpful the framework becomes.

I migrated two systems in parallel, my development and production environments, running xubuntu and debian etch respectively.

The first problem, as always is the case with ruby, is the documentation. In one sense, I quite like the anarchy of a completely disorganised documentation system cobbed together only by a decent search engine, but I must say that with this rails upgrade I felt very much on my own in terms of help and support, having to glean tips and derive solutions from several blogs, wikis and rdocs.

The next wall I ran into was related to the rubygem system. Far from the ‘packaging bliss’ I was sold on initially, the source index file is now so large that it completely eats the system memory and swap on my old development laptop, taking an extremely long time to complete. I learned the –no-update-sources option for gem installs, which avoids lengthly index updates. Eventually, I used gems to update rails:
gem update rails
There may have been some more commands in there. On my ubuntu laptop, I found that once I had a copy of rails 2.2.2 that everything broke, asking for a 1.3.1 version of rubygems. Using the ordinary method gem update –system didn’t work; claiming that there was nothing to update. Instead, I downloaded the gem from http://www.rubygems.org/ and installed it myself:
sudo gem install –no-update-sources –local rubygems-update-1.3.1.gem
sudo update_rubygems
Then I replaced the missing mysql adapter. Rails 2.2.2 dropped the mysql adapter from the framework, meaning that I have to re-install it to keep my app running. I will note here that the functionality that sold me on rails the first time I saw it has now been removed by default; as though rails introduced a quick method of making web-based views on mysql databases to catch peoples attention, and now they’re slowing leading them away to some other technological viewpoint. Anyway, to fix on linux I needed the mysql client development headers, found in the libmysqlclient15-dev package:
sudo apt-get install libmysqlclient15-dev
sudo gem install mysql
I was ready to run my unit and functional tests, to see what broke. In short, my application had problems with deprecated features and third-party plugins:

  • In places, my application used request.relative_url_root to build URLs to resources relative to the public folder (I didn’t find a decent way of doing this without calling this method, I’d like to have something similar to image_tag). Anyway, the method was deprecated, replaced with ActionController::Base.relative_url_root. The new method returns nil if the application is deployed in the root of the domain (no context), which broke some calls which were building URL strings, so I created my own helper method to retrieve the context and changed all calls to it.
  • The country_select helper has been removed. There is a replacement plugin available at http://github.com/rails/country_select/tree/master, but I found that it doesn’t work with rails 2.2.2. To avoid ‘wrong number of arguments’ errors, the following tweak is needed on line #7 of country_select.rb in the vendor/plugins/country_select/lib folder:
    InstanceTag.new(object, method, self, nil, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
    InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
  • The acts_as_commentable, acts_as_voteable and acts_as_rateable plugins all broke, giving ‘Unitialized constant’ errors. This is fixed by tweaking the init.rb file for each plugin to ensure the plugin library files are loaded correctly:vendor/plugins/acts_as_commentable/init.rb:
    require File.dirname(__FILE__) + ‘/../acts_as_voteable/lib/acts_as_voteable’
    require File.dirname(__FILE__) + ‘/../acts_as_voteable/lib/vote.rb’
    ActiveRecord::Base.send(:include, Juixe::Acts::Voteable)

    require File.dirname(__FILE__) + ‘/lib/acts_as_commentable’
    require File.dirname(__FILE__) + ‘/lib/comment’
    ActiveRecord::Base.send(:include, Juixe::Acts::Commentable)
    vendor/plugins/acts_as_rateable/init.rb:
    require File.dirname(__FILE__) + ‘/lib/acts_as_rateable’
    require File.dirname(__FILE__) + ‘/lib/rating’
    ActiveRecord::Base.send(:include, Juixe::Acts::Rateable)
    vendor/plugins/acts_as_voteable/init.rb:
    require File.dirname(__FILE__) + ‘/lib/acts_as_voteable’
    require File.dirname(__FILE__) + ‘/lib/vote.rb’
    ActiveRecord::Base.send(:include, Juixe::Acts::Voteable)

  • Unobtrusive Date Picker became obtrusive, requiring a complete removal from my application and re-install from http://github.com/thincloud/unobtrusive_date_picker/tree/master. Make sure the version you download has the correct copy of 12_hour_time.rb, I found that the one installed via git was the old version.

Hence I finally could run the application on the rails 2.2.2 framework. The debugging continues….

Continue Reading »
1 Comment