Rails 5 Upgrade: routes.rb file cleared out
Asked Answered
L

2

8

I am upgrading a Rails app from 4.2.x to 5.0.x. After I updated all my Rails-related gems in Gemfile, I ran the rails task for updating all my files to conform to the newest version, as per the upgrade guide:

rails app:update

There were many conflicts in this command, so I pressed a to accept all conflicts and then review them manually before committing them. My main concern is what happened to the config/routes.rb file. Basically, the entire contents of the file, save for the Rails.application.routes.draw block and a single comment about the DSL added to the end of the file, were kept. All routes that have been added to the app over the years were cleared out, not to be found in any other file.

This issue doesn't block me, I'll simply checkout the file to bring it back to its former state. However, what especially concerns me is that an essential file was cleared out in what appears to be a normal situation for upgrading a Rails version. I'd like to see if anyone else has run into this issue, whether this is expected, what's going on. Comments from Rails maintainers are welcome. Thank you.

Lorislorita answered 20/7, 2017 at 14:10 Comment(1)
Normally use test packs that I've written whilst performing upgrades. Will look at the upgrade guide for anything major and then boot the version up a level before running tests and then fixing any problems.Latton
R
7

The app:update task is just a slightly modified version of the task that creates a new Rails application. It writes out files under config/ and bin/ based on the templates from the new Rails version. If you selected a to accept all conflicts, then that simply means that Rails is going to overwrite any differing files with its own copy without asking you. This is normal and expected. If you don't want that behavior, then don't press a.

config/routes.rb is almost certainly the one file under config/ that will differ almost completely from the empty boilerplate file. Realistically, Rails can't be expected to parse your custom changes and merge them with a new template.

For what it's worth, I like to start out doing exactly what you did, with a clean working directory just let the app:update task overwrite anything it wants to, and then go through all the changes with a side-by-side, SCM-aware diff tool like vim-fugitive to stage or discard the differences.

Rowan answered 9/7, 2018 at 19:34 Comment(0)
A
-2

Well, just don't accept all conflicts, take a look in each one of it. Making version upgrades of 1 level of magnitude may change a lot of things and the process takes a while.

First take a look on the changes in the framework and do the process carefully. You may be breaking a lot more stuff that you are not noticing:

http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-2-to-rails-5-0

Anthropolatry answered 20/7, 2017 at 14:44 Comment(1)
The idea around my question is not that I shouldn't be manually inspecting the changed files from rails app:update, it's a given that I shouldn't just be accepting changes without ensuring that they fit in my app. My question is more around the concern of that I don't understand how the default logic of this rails task is to "clear out routes.rb".Lorislorita

© 2022 - 2024 — McMap. All rights reserved.