Ruby and Rails deprecation warnings and how to fix them

Updated . Posted . Visible to the public.

Add deprecation warnings and their solution or link to available solutions.

Global access to Rake DSL methods is deprecated. Please include Rake::DSL into classes and modules which use the Rake DSL methods.

Open your Rakefile and add the following line above YourApp::Application.load_tasks:

YourApp::Application.class_eval do
  include Rake::DSL
end

Use of ole/file_system is deprecated. Use ole/storage (the file_system api is recommended and enabled by default).

Update the spreadsheet gem Show archive.org snapshot to its latest version (has no dependencies). See this issue Show archive.org snapshot .

The :overwrite_params option is deprecated. Specify all the necessary parameters instead.

See this note

Kernel#returning has been deprecated in favor of Object#tap. (called from enable_activerecord at /.../gems/will_paginate-2.3.14/lib/will_paginate.rb:39)

Update will_paginate gem Show archive.org snapshot to version >= 2.3.15

Object#id will be deprecated; use Object#object_id

This warning occurs for non active record models. Overwrite the id-Method in the model (no method body needed)

warning: default `to_a' will be obsolete

Don't use Array(...) or #to_s to coerce arbitrary objects into an Array. Use #listify instead.

Using #request_uri is deprecated. Use fullpath instead

Upgrade gems that call #request_uri. Some gems that do this (like ssl_requirement) are no longer maintained. In that case you can copy the following hack to config/initializers/undeprecate_request_uri.rb:

module ActionDispatch
  module Http
    module URL
      def request_uri
        fullpath
      end
    end
  end
end

Finding deprecation warnings

If Ruby complains about a deprecated method being, called, you can overwrite this method, so it raises an error. This will give you a stack trace during runtime:

Object.class_eval do
  def to_a
    raise 'trace'
  end
end

Unfortunately this won't help you with every deprecation warning you will encounter. We tried to use our debug message hunter for this purpose, but to no avail.

Ulrich Berkmüller
Last edit
Arne Hartherz
Keywords
warning, error, deprecation, update, upgrade, solve, solution
License
Source code in this card is licensed under the MIT License.
Posted by Ulrich Berkmüller to makandra dev (2011-03-22 08:23)