|
||||||||||
|
||||||||||
July 5, 2008 Recently I was tasked with upgrading a working Rails 1.2.6 application to version 2.0.2. Here are the majority of issues I found and their fixes/workarounds: Old reverse_proxy_plugin = broken functional tests:The units tests were fine, but all the functional tests were broken. Something like this:
post :list, { :site_id => site.id }, { :user_id => user.id }
would complain like: ArgumentError: wrong number of arguments (1 for 2) I found it was the reverse_proxy_fix plugin causing the issue. The Rails 1.x version fails to provide accommodations for functional test helpers in its url_rewriter code. I found there is a new version for Rails 2.x here: http://www.napcsweb.com/blog/2008/03/07/reverse-proxy-fix-1050-released/ script/plugin install http://svn.napcsweb.com/public/reverse_proxy_fix Make sure and backup your vendor/plugins/reverse_proxy_fix/lib/config.rb file if you have any customizations. Active Record Store + Oracle CLOB:This app uses :active_record_store for secure session storage, as defined in environment.rb: config.action_controller.session_store = :active_record_store Using `rake db:sessions:create`, you end up with a database migration like: def self.up create_table :sessions, :force => true do |t| t.string :session_id, :null => false t.text :data t.timestamps end add_index :sessions, :session_id add_index :sessions, :updated_at end But that won't work. The 'data' field ends up being an Oracle CLOB type and ActiveRecord won't write session data to it (for whatever reason). I changed the migration to produce a varchar(4000) and that seems to work fine. t.string :data, :limit => 4000 Plugins:Many non-common-case features from Rails 1.x were factored out into separate plugins, the 'auto_complete_field' being one of them. I had to add it back using: script/plugin install auto_complete You'll want to check this URL for other plugins your app may need after upgrading: http://svn.rubyonrails.org/rails/plugins/ Using protect_from_forgery with Javascript helpers:The new 'protect_from_forgery' feature is on by default in Rails 2.x. It's a welcome addition as it's great for preventing cross-site-scripting attacks on web forms. But when testing an autocomplete field I found I was getting ActionController::InvalidAuthenticityToken errors. The code auto_complete_field was rendering didn't contain the required authenticity token: var form4_surgeon_auto_completer = new Ajax.Autocompleter('form4_surgeon', 'form4_surgeon_auto_complete', '/form4/autocomplete_surgeon', {}) So I just added it myself: var form4_surgeon_auto_completer = new Ajax.Autocompleter('form4_surgeon', 'form4_surgeon_auto_complete', '/form4/autocomplete_surgeon?authenticity_token=<%= form_authenticity_token %>', {}) A patch has been provided for a future Rails version: http://dev.rubyonrails.org/ticket/10059 But in the meantime it's pretty easy to work around. Controller Action Names:This app had a controller action name 'start', as in: http://localhost:3000/study/start None of the instance variables existed in the view, and calls to 'debugger' were being ignored. After a while I realized 'start' was probably a reserved keyword in Rails 2.x. I changed the action and view names to 'new_study' and it began to work again. Strange however, 'start' isn't on the Rails reserved keyword list: http://wiki.rubyonrails.org/rails/show/ReservedWords
|
|
|||||||||
|
||||||||||