Posted almost 6 years ago. Visible to the public. Repeats.

Ruby and Rails deprecation warnings and how to fix them

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

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

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 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.

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Author of this card:

Ulrich Berkmueller
Last edit:
about 2 years ago
by Dominik Schöler
warning, error, deprecation, update, upgrade, solve, solution
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Ulrich Berkmueller to makandropedia