The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Engines 2.0 and Rails 2.0 Upgrade Gotchas

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Nathaniel Brown

Posts: 54
Nickname: nshb
Registered: Oct, 2005

Nathaniel Brown is Technology Consultant in Vancouver, Canada
Engines 2.0 and Rails 2.0 Upgrade Gotchas Posted: Dec 29, 2007 2:09 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Nathaniel Brown.
Original Post: Engines 2.0 and Rails 2.0 Upgrade Gotchas
Feed Title: Nathaniel Brown
Feed URL: http://feeds.feedburner.com/nshb
Feed Description: Insight as a professional Technology Consltant and Photographer.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Nathaniel Brown
Latest Posts From Nathaniel Brown

Advertisement

I just updated a couple of my personal projects to Rails 2.0 and Engines 2.0 and I ran into a few problems once the gems were upgraded.


sudo gem update --system
sudo gem update rails -y

Change your svn:externals for your engines plugin to point to the trunk.


cd project/root
svn pe svn:externals vendor/plugins

Add/update the following:


engines    http://svn.rails-engines.org/engines/trunk/

First, the config.plugins needs to change from "*" to :all. So your new line would look something like this:


config.plugins = [:engines, :all]

Change the Rails version in your environment.rb.


RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION

Adding the boot line to your environment.rb (above the initializer).


require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')

Adding some new session config options to your environment.rb as well:


  config.action_controller.session = {
    :session_key => '_www_example_com-trunk_session',
    :secret      => 'Long string for security. Run "rake secret" to generate'
  }

Utilization of the new /config/initializers to be used on load (optional). Use these for plugin or namespaced configuration options. I use them quite a bit for the Toolbawks suite I am building.

For your project, strip environment.rb down as much as you can by extracting and spliting the options out into individual.rb files inside initializers. This will clean it up and keep it much more organized for future releases of Toolbawks in particular.

Not sure if this wasn't in 1.2.6 or not, but I seen an update to the root route change in the new default Rails project. Change your empty route (root url) to be like this, but with your own controller/action:


  map.root :controller => "collections", :action => 'show'

Migrations have also been updated, but when I tried to use both the 1.2 syntax as well as the 2.0 syntax, it worked fine, so not much of a gotcha:

Rails 1.2 Migrations syntax


    create_table :collections do |t|
		t.column :title, :string
		t.column :description, :text
		t.column :count, :integer
		t.column :created_by, :integer
		t.column :created_at, :datetime
		t.column :modified_at, :datetime
    end

Rails 2.0 Migrations syntax


    create_table :collections do |t|
		t.string :title
		t.text :description
		t.integer :count
		t.integer :created_by
		t.datetime :created_at
		t.datetime :modified_at
    end

As you can see the 2.0 syntax is much cleaner, but for all your old migrations this is sorta a waste of time to update as far as I'm concerned. So refactor when needed, and use the new syntax from now on.

The breakpoint server has changed, and the environment.rb config option is no longer needed. This really doesn't do much if it's in the config, but to get rid of the deprecation warning, I suggest removing it:


config.breakpoint_server = true

Pagination has been removed from Rails core, so you will need to upgrade that. I suggest using the will_paginate plugin. Checkout their site for upgrade instructions. Or you can use the classic_pagination if you don't need serious performance increases. The code is claimed to be dead for classic_pagination, so I suggest upgrading now to will_paginate, to avoid confusion later.

I had a problem with some of my logger code, so I added this line in one of my lib files to give me a global logger function I can use anywhere. This will later be extracted into a plugin for more comprehensive logging functionalities, but for now a simple addition of these three lines worked:


def logger
  RAILS_DEFAULT_LOGGER
end

Engines.current.version no longer exists, so if you want that sort of functionality to see what version the engine is, add a new property to your plugin like so:


module DatetimeToolbawks
  mattr_accessor :version
  self.version = false
end

And add this to your init.rb script within your plugin.


DatetimeToolbocks.version = Proc.new { File.open(File.join(RAILS_ROOT, 'vendor', 'plugins', 'datetime_toolbawks', 'VERSION'), 'r').readlines[0] }

Some methods have been entirely removed now, such as render_file and render_json. That means you must update them to get a functioning Rails 2.0 app.


      render :file => rescues_path("layout"), :status => response_code_for_rescue(exception)

That's it for now. Pretty sure I missed a few things, so when I update another app to Engines/Rails 2.0 I'll be sure to refresh this page with any additional upgrade steps.

All the Toolbawks plugins are now functioning for Rails 2.0, so it would be wise to get on board, reap the benefits of the

Read: Engines 2.0 and Rails 2.0 Upgrade Gotchas

Topic: Installing Django with PostgreSQL on Ubuntu Previous Topic   Next Topic Topic: rfacebook Q&A with Duane Morin - Connect At College rfacebook Sighting

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use