Upgrading Your Rails App: Shims and Monkey Patches Explained

Photo by Jamie Haughton on Unsplash

Upgrading your Rails App with Shims and Monkey Patches

However, as Ruby/Rails advances, deprecated methods and past version functionality may need to be moved to shims and monkey patches.

This guide will provide an overview of what shims and monkey patches are, why they are important for upgrading your Rails version, and the best practices for utilizing them in your application.

What are Shims and Monkey Patches?

Monkey patches go even deeper, modifying existing code to provide new behavior. While shims and monkey patches can provide a cost-effective and quick solution to the problem of rearranging code when upgrading a Rails version, there are inherent risks with using them.

Why are Shims and Monkey Patches Important for Upgrading your Rails Version?

A good example is a feature that was deprecated in a previous version of Rails and no longer appears in current versions. If the feature is important to an application, a shim or monkey patch can be used to revive it and make it work in the new version.

Best Practices for Utilizing Shims and Monkey Patches

When using a shim or a monkey patch, take the time to understand exactly how the underlying framework behaves. This will help to ensure that the fix being applied is valid and does not override any existing functionality.

It’s also important to understand the risks associated with using shims and monkey patches. While these methods can be cost-effective and quick-to-implement solutions for upgrading your Rails version, they may also introduce unexpected behavior and security issues.

Conclusion

References

- Agile WebApp Development with Rails 6 — Sam Ruby, David Copeland

- Ruby on Rails Tutorial: Learn Web Development with Rails (Addison-wesley Professional Ruby) — Michael Hartl

- Rails 5 Way, The (Addison-Wesley Professional Ruby Series) — Obie Fernandez

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pablo Adell

Hello there!! My name is Pablo, I am a Full-Stack Software Engineer at Affirm, focused mainly in Ruby on Rails and React. I hope you enjoy my content!