Few weeks back I did rails upgrade for my current project from rails 2.3.5 to rails 3.0.9 (on Windows 7).
I began with rails 3 upgrade guide. So, first step was to install ruby 187, which I already had on my system with pik
There is a good series on rails on upgrading to rails 3 from Ryan Bates:
http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-1
http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-2
http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-3
Some how the rails-upgrade-plugin did not work for me (as I was working on Windows 7) .
I then followed the-path-to-rails-3-approaching-the-upgrade step-by-step and I got application 80% upgraded, the rest 20% was a tough part.
In this blog, I am writing about challenges I faced in this process.
I began with rails 3 upgrade guide. So, first step was to install ruby 187, which I already had on my system with pik
There is a good series on rails on upgrading to rails 3 from Ryan Bates:
http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-1
http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-2
http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-3
Some how the rails-upgrade-plugin did not work for me (as I was working on Windows 7) .
I then followed the-path-to-rails-3-approaching-the-upgrade step-by-step and I got application 80% upgraded, the rest 20% was a tough part.
In this blog, I am writing about challenges I faced in this process.
- Installing rails 3.0.9 gem:
Somehow gem install rails shown errors:
C:\myapp>gem install rails
Successfully installed rails-3.0.9
1 gem installed
Installing ri documentation for rails-3.0.9...
file 'lib' not found
Installing RDoc documentation for rails-3.0.9...
file 'lib' not found
I used,
C:\myapp>gem install rails --no-rdoc --no-riSuccessfully installed rails-3.0.9
1 gem installed - routes.rb
I had to update the routes.rb file and I found one really helpful link: http://stackoverflow.com/questions/3103765/routing-in-rails-3-map-with-options - Deprecation warning for cookie_store:
DEPRECATION WARNING: ActionController::Base.session= is deprecated. Please configure it on your application with config.session_store :cookie_store, :key => '....'. (called from C:/myapp/config/initializers/session_store.rb:7)
So, I did:
module Myapp class Application < Rails::Application config.session_store :cookie_store, :key => '_myapp_session', :secret => 'some-secret-string-very-long'
Also, I removed C:/myapp/config/initializers/session_store.rb file.
Reference: http://stackoverflow.com/questions/3720379/sqlsessionstore-in-rails-3 and http://apidock.com/rails/ActiveRecord/SessionStore - Logging the deprecation warnings
I saw another warning:
You did not specify how you would like Rails to report deprecation notices for your development environment, please set config.active_support.deprecation to :log at config/environments/development.rb
So, I updated development.rb (and other.rb files):
Myapp::Application.configure do config.active_support.deprecation = :log - consider_all_requests_local warning
DEPRECATION WARNING: ActionController::Base.consider_all_requests_local= is deprecated. Please configure it on your application with config.consider_all_requests_local=.
So, I added this snippet in config/environments/development.rb
Myapp::Application.configure doconfig.consider_all_requests_local= true - Some easy once
1. DEPRECATION WARNING: RAILS_ENV is deprecated. Please use ::Rails.env.
So, wherever I was using RAILS_ENV, I replaced with Rails.env
2. DEPRECATION WARNING: RAILS_ROOT is deprecated. Please use ::Rails.root.to_s.
So, wherever I was using RAILS_ROOT, I replaced with Rails.root.to_s - ActionMailer warnings
1. When you need to set character set for action mailer, you specify in initializer.rb, which throws this warning:
DEPRECATION WARNING: ActionMailer::Base.default_charset=value is deprecated, use default :charset => value instead
I passed hash to the default method in application.rb:
Myapp::Application.configure dodefault :charset => 'utf-8'
2 Similarly the mime version we set in initializers:
DEPRECATION WARNING: ActionMailer::Base.default_mime_version=value is deprecated, use default :mime_version => value instead.
I passed hash to the default method in application.rb:
Myapp::Application.configure dodefault :mime_version => '1.0'
3. For multipart emails the setting has to be adjusted:
DEPRECATION WARNING: ActionMailer::Base.default_implicit_parts_order=value is deprecated, use default :implicit_parts_order => value instead
This is again can be passed to default method:
Myapp::Application.configure dodefault :parts_order => [ "text/plain", "text/enriched", "text/html" ] - html_safe in view?
For 2-3 hours I struggled to find the reason, why the select tag was not producing the tags. When I found it I understand that this is again a security addition to convert strings into html safe form. So, all your '<' will be converted to '<' and all '>' will be converted into '>'. I actually added .html_safe at the end of each string in view and that showed all the tags finally.
Reference: rails-3-select-tag-not-producing-dom-elements - Removed config.action_view.cache_template_loading, use config.cache_classes instead
Reference: https://github.com/rails/rails/commit/83e29b9773ac113ceacb1e36c2f333d692de2573 - Rspec
I was using rspec and here is the deprecation warning I got:
*****************************************************************
DEPRECATION WARNING: you are using a deprecated constant that will be removed from a future version of RSpec.
C:/cit/spec/controllers/activity_logs_controller_spec.rb:1:in `require'
* Spec is deprecated.
* RSpec is the new top-level module in RSpec-2
***************************************************************
***************************************************************
DEPRECATION WARNING: you are using deprecated behaviour that will be removed from a future version of RSpec.
C:/cit/spec/spec_helper.rb:17
* Spec::Runner.configure is deprecated.
* please use RSpec.configure instead.
So, I have to use rspec-rails-2 which supports rails 3.
Reference: http://groups.google.com/group/cukes/browse_thread/thread/40c4c2aea1c07afe/cb63eb7f0b733646?lnk=raot - Ajax stopped working
I was using jQuery as javascript library, and I found somehow the ajax calls stopped working after the upgrade. I later found that there is a security threat and a fix for that is available
Here is what I had to do:
Step#1. In application.html.erb, I had to include csrf_meta_tag:
<%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
Step#2. I added this snippet to application.js:
$(document).ajaxSend(function(e, xhr, options) { var token = $("meta[name='csrf-token']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token); });
Reference: csrf-protection-bypass-in-ruby-on-rails - RackBaseURI instead of RailsBaseURI
I was using RailsBaseURI in apache, but after upgrade to Rails 3, I had to update it to RackBaseURI
Reference: RackBaseURI - Last but not least, I was using valid? method in helper to check if the object is valid or not and based on that I was displaying certain fields, which was working fine in Rails 2. In Rails 3 valid? method will trigger validations as well, which caused field_with_errors div to show-up all the time (even when the validation should not happen). I changed the logic to not use valid? method to display other fields and it solved the problem.