
Accelerating Legacy Code Updates with AI: A Journey from Ruby 2.6.5 to 3.2.2 and Rails 5.2.0 to 7.1.2
Published on December 11, 2024
In the ever-evolving world of software development, staying up-to-date with the latest versions of languages and frameworks is crucial for security, performance, and compliance. Recently, I embarked on a journey to update one of my personal Ruby on Rails applications—a project that hadn’t seen any significant changes in over three years. The task was daunting: migrating from Ruby 2.6.5 to 3.2.2 and from Rails 5.2.0 to 7.1.2, all while ensuring that the application remained functional and secure.
What could have been a tedious and time-consuming process turned into an exhilarating experience, thanks to the power of large language models (LLMs) and modern AI tools. In this blog post, I want to share how leveraging AI not only streamlined the migration but also made it an enjoyable endeavor.
The Challenge: Updating a Neglected Application
Hosted on Heroku, my application had been running on an outdated stack that had reached its end-of-life three years prior. Heroku’s notifications about the deprecated stack finally pushed me to take action. The primary goals were:
- Upgrade Ruby from 2.6.5 to 3.2.2
- Upgrade Rails from 5.2.0 to 7.1.2
- Update various gems, including significant changes in the Shrine gem for file uploads
- Ensure compatibility with the JavaScript library Uppy for the upload interface
Given the extensive changes in both Ruby and Rails over multiple major versions, along with updates needed for gems like Shrine, I anticipated a steep learning curve and a significant time investment.
Enter AI: Cursor IDE, ChatGPT, and Anthropic
To tackle this challenge efficiently, I decided to leverage AI tools:
- Cursor IDE: An integrated development environment with the capability to index my entire codebase.
- ChatGPT and Anthropic’s Claude: Advanced LLMs that provide contextual assistance and code suggestions.
Indexing the Codebase with Cursor
Using Cursor IDE, I indexed the entire codebase of my application. This feature allowed me to reference @codebase
in the chat window, enabling the AI to understand the context of my project fully. It was incredible to see the AI navigate through my codebase, offering precise suggestions tailored to my application’s specific needs.
Real-Time Assistance with LLMs
With the codebase indexed, I engaged in a dynamic conversation with ChatGPT and Claude. Their ability to understand the context and provide actionable advice was nothing short of amazing. For instance, when dealing with deprecated methods or changes in Rails conventions, the AI would not only point out the necessary adjustments but also explain the reasoning behind them.
Updating Gems and External Libraries
One of the significant hurdles was updating the Shrine gem, which I use in combination with the Uppy JavaScript library for file uploads. Shrine had undergone substantial changes over the years, and manually sifting through the documentation and changelogs would have been time-consuming.
By dropping the URLs of the Shrine documentation and the Shrine changelog into my chat with Claude, the AI quickly synthesized the information. It guided me through the necessary code modifications to ensure that my upload functionality worked seamlessly with the updated gem versions.
The Outcome: A Rapid, Enjoyable Migration
What could have been a week-long project was condensed into a couple of days. The AI tools acted like an expert pair programmer, accelerating the migration process while enhancing my understanding of the changes. Here’s what stood out:
- Efficiency: Tasks that typically require extensive research and debugging were completed in minutes.
- Learning Experience: The AI didn’t just provide answers—it explained the “why” behind each suggestion, deepening my understanding.
- Enjoyment: The process was genuinely fun. Collaborating with AI brought a new level of engagement to coding.
Reflections on AI in Software Development
This experience underscored the transformative potential of AI in software development:
- Personalized Assistance: AI models can offer bespoke help, tailored to the specific context of your project.
- Bridging Knowledge Gaps: They help bridge gaps in knowledge, especially when dealing with multiple version changes and deprecated features.
- Accelerating Development: AI can significantly reduce the time required for complex tasks, allowing developers to focus on higher-level problem-solving.
Conclusion
Updating a legacy application across multiple major versions of Ruby and Rails was no small feat. However, with the aid of modern AI tools like Cursor IDE, ChatGPT, and Anthropic’s Claude, the process was not only manageable but also enjoyable. This experience has left me excited about the future of AI in software development and eager to explore more ways to integrate these tools into my workflow.
If you’re facing a similar challenge or simply want to enhance your development process, I highly recommend giving these AI tools a try. They might just transform the way you code.
Happy coding!
Resources:
- Uploading image with Uppy through Shrine returns 405 Method Not Allowed
- Shrine GitHub Issue: S3 presign_endpoint returns 403 Forbidden
- AWS Question: POST uploads to S3 bucket failing with HTTP 405
- S3 Uploads: Proxies vs Presigned URLs vs Presigned Posts
- Shrine Documentation: Direct S3 Upload
- Shrine Guide: Upgrading to Version 3
Categories: Web Development
Tags: Ruby , Rails , Migration , AI , Anthropic , Claude , Cursor IDE