Thursday, September 18, 2008

Upgrading to Rails 2.x

Here's a short (?) list of issues encountered when upgrading from Rails 1.2.6 to Rails 2.x (in my case it was Rails 2.1.1).

  • first thing is run that rake task for deprecation (place it in your lib/tasks as deprecated.rake and then run rake deprecated). It should give you a few things to change
  • Change @request, @session[], @params[] by removing @ sign in front of them.
  • Change <%= start_form_tag ... %> to <% form_for :action => '...' do %>
  • Change <%= end_form_tag %> (where the above start_form_tag appears) to <% end %>
  • Change find_first(["..."...]) to find(:first, :conditions => ["...",...]) (Note: I believe rake deprecated did not catch all of these initially!)
  • Remove model directive from your controllers
  • Follow the rake task deprecation list until all is done (I did all except the paginator at first since I wasn't sure what to do)
  • Install rails with dependencies (gem install -y rails). I got Rails 2.1.1.
  • Update gem (gem update --system)
  • In your rails application root you'd need to run rake upgrade (emm.... my memory fails me right now - I think its that?). This sort of updates the config/... files from what I gathered - namely the config/boot.rb as well as public/javascript files (I notice that prototype is after the upgrade).
  • Update config/environment.rb change RAILS_GEM_VERSION = '1.2.6' unless defined? RAILS_GEM_VERSION to RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION (or whatever your Rails 2.x version is)
  • If you used observers in your controllers remove them from there (look for observer :your-model-name_observer in your controllers)
  • Add observers into config/environment.rb (inside do |config| section add config.active_record.observers = :your-model-name_observer)
  • Update act_as_versioned plugin with the latest from git (if you don't change it this plugin apparently completely breaks the activerecord setter and you'd get NoMethodError on normal model object setters, especially with ajax in-place editor)
  • Add config.action_controller.session = { :session_key => "_your-app_session_", :secret => "random security string" } to the same config/environment.rb section as above. You can generate a big nice security hash string by doing rake secret.
  • I'm using old paginator (found in your typical Rails book) so I installed the classic_pagination plugin to make it work again (yes, yes, will replace it once I get the app running again)
  • I had a patch of some sort for in_place_editing (sorry can't remember where I got it or what was it but I know it was actually useful - I think relating to editing blank/empty data). Remove that altogether (it was in my lib/extensions.rb - things like ActionView::Helpers::JavaScriptMacrosHelper.class_eval do ...).
  • Install super_inplace_controls plugin (ruby script/plugin install as a replacement for your normal in_place_editor. Add to your layout file: <%= stylesheet_link_tag "in_place_styles" %> as well as somewhere inside the content area of the layout file a placeholder div for errors with ID inplace_error_div.
  • Change views which used the old style in_place_editor's <%= in_place_editor_field :rawdata, :col1 %> with <%= in_place_text_field :rawdata, :col1 %>
  • Leave the in_place_edit_for :model :field directives in your controller as they were
  • I changed ActionMailer::Base.server_settings = { ... in environment to ActionMailer::Base.smtp_settings = {.
  • One last note: I have other applications running on Rails 1.2.x which I still want to have so make sure you do NOT remove old gems that these might be removing. I believe running gem clean would do that so don't do it unless you want to jump into fixing all the other applications right away)
Wouldn't it be nice if upgrades were not a big deal/problem?

I've later discovered a problem with mongrel - it simply won't run as windows service. I'm using mongrel_service for this. The error shown is something along:
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- c:/ruby/
lib/ruby/gems/1.8/gems/mongrel_service-0.3.4-x86-mswin32/lib/mongrel_service/init.rb (MissingSourceFile)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb:134:in `load'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:203:in `each'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:203:in `each'
from c:/ruby/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb:112:in `load'
... 11 levels...
from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
Turns out that the fix is pretty straight forward: change your gem folder name of mongrel_service (should be under your [ruby root]/lib/ruby/gems/1.8/gems/) from mongrel_service-0.3.4-i386-mswin32 to mongrel_service-0.3.4-x86-mswin32 (I suppose your version could be different). Thanx for te tip from this post.

No comments: