Search code examples
ruby-on-railsrubyruby-on-rails-3rails-3-upgrade

Upgrading from Rails 2 to 3: undefined method use_standard_json_time_format


I am trying to upgrade Rails from 2.3 to 3.1. I watched the upgrade video from Railscast but I am having some difficulties.

Steps I followed:

  1. Create a separate Rails 3 branch from stable branch.
  2. Update and reload RVM to the latest version.
  3. gem install rails -v 3.0.20.
  4. rails upgrade check and rails upgrade backup using Rails upgrade plugin.
  5. rails new . --skip-active-record

When I start the server I am getting this error:

initializers/new_rails_defaults.rb:13:in `<top (required)>': undefined method `use_standard_json_time_format=' for ActiveSupport:Module (NoMethodError)

Can anyone please help?


Solution

  • The default for use_standard_json_time_format changed between Rails 3.0.20 and 3.1.0 from false to true, so depending which version you're aiming for (your question mentions both), you might be able to drop the configuration.

    If you're cherry-picking ActiveSupport modules, make sure you've required ActiveSupport::JSON::Encoding, which defines the method.

    require 'active_support'
    require 'active_support/json/encoding'
    

    And since ActiveSupport.use_standard_json_time_format is just delegating to ActiveSupport::JSON::Encoding, you can also try calling it directly on the latter.

    ActiveSupport::JSON::Encoding.use_standard_json_time_format = true