As we upgrade our application’s Rails version, we often come across deprecation warnings.
In the above case, we remove these deprecation warnings by replacing
But, when developing new features after it, we might end up using deprecated
We might ignore these deprecation warnings and on next Rails upgrade we will
encounter new issues.
To avoid the above case, Rails has introduced
disallowed deprecations in ActiveSupport.
Once we have removed deprecations from codebase, we configure these deprecations
disallowed. If a disallowed deprecation is used, it will be treated as a failure
and raise an exception in development or test environment. In production, we log the
deprecations as error.
We can configure the
disallowed_warnings in our
config file as below:
Configuration rules as seen above are defined in an array. Array elements can be String, Symbol or Regexp. In each case we try to match the array element as a substring or regex match in our warning message.
Disallowed configuration can be set to raise exception
for all deprecation warning by using
:all symbol as below:
We can set the behavior for disallowed messages to either
By default, it is set to
:raise in development and test environment and
in production environment.
We can temporarily re-allow disallowed deprecation using the
We can also pass an array of string, symbol or regular expression elements to this method.
.allow method call also be called conditionally as shown below