I recently migrated a Rails 2.3.8 app to Rails 3.0.0Beta4. Here is what I learned through that exercise.
1) Install rails
sudo gem install rails --pre
2) Install rails upgrade helper plugin
rails plugin install git://github.com/rails/rails_upgrade.git script/plugin install git://github.com/rails/rails_upgrade.git /Library/Ruby/Site/1.8/rubygems.rb:233:in `activate': can't activate rails (= 2.3.8, runtime) for [], already activated rails-3.0.0.beta4 for [] (Gem::LoadError)
Couldn’t proceed with that error. At this point, after spending an hour, I gave up on trying to move my existing Rails2.x app as is to Rails3 since it is clear that the boot process is different for Rails3 and keeping the existing boot.rb etc will create more chaos.
3) Create a new rails 3.0.0 application
rails new app_30
cd app_30
Copy over app/controllers, app/views, app/lib, app/models, config/database.yml from old to new
4) Start server script/rails server (script/server won’t work)
5) Add gem ‘mysql’, ’2.8.1′ to gemfile
6) Set the root correctly in routes.rb file. For some reason it doesn’t find default controller.
root :to => "nav#index"
7) Install all the missing gems and add them to gemfile with appropriate versions, if need be. If you have legacy plugins, the newer gems don’t seem to work correctly, stick to the legacy plugins and move them over to the new app.
paginate_by_sql breaks since add_limit! is removed from ActiveRecord::Base. Fix paginate by sql to do this:
module ActiveRecord class Base def self.find_by_sql_with_limit(sql, offset, limit) sql = sanitize_sql(sql) find_by_sql(sql + " LIMIT #{offset},#{limit}") end def self.count_by_sql_wrapping_select_query(sql) sql = sanitize_sql(sql) count_by_sql("select count(*) from (#{sql}) as x") end end end
9) Add the following two routes to routes.rb. Without these two routes /controller/action is not recognized by default.
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'
10) ActionDispatch::Cookies::CookieOverflow error. Set your session_store to be active_record_store. Change this in config/initializers/session_store.rb
Rails.application.config.session_store :active_record_store, :key => '_mygreatapp_30_session'
11) Rails generated HTML tags are HTML escaped by default. So if you did something like
<%=link_to “ foobar” … %>, the would be escaped and represented literally on screen.
Likewise, if you had code that did
<%= getImage %> and getImage helper returned “<a href=”…”><img src=””/></a>, the returned string would be escaped. Use <%= image_tag(getImage) %> and change the getImage to return just the image path.
12) If you are sure that the code is returning safe HTML, then do this:
<%= helper_returning_html.html_safe %>
or
<%= raw helper_returning_html %>




