Read more

Ruby and Rails deprecation warnings and how to fix them

Ulrich Berkmueller
March 22, 2011Software engineer

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.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

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

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

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.

Posted by Ulrich Berkmueller to makandra dev (2011-03-22 09:23)