Skip to content

Instantly share code, notes, and snippets.

@louisscruz
Created July 3, 2017 06:20
Show Gist options
  • Save louisscruz/f138e5520fc9e184aebbb36dc9afff27 to your computer and use it in GitHub Desktop.
Save louisscruz/f138e5520fc9e184aebbb36dc9afff27 to your computer and use it in GitHub Desktop.
On Updating To Rails 5

On Updating To Rails 5

Hello, fellow TA. We're really glad to have you on the Rails 5 update team!

Our students are already using Rails 5, but our curriculum is not. We're going to fix that.

We'll be updating the curriculum to Rails 5.1.2. Before going on, I recommend you check that you have that specific version installed. Run rails -v. If you're not up-to-date, run the following: gem install rails --version=5.1.2.

In this document, I'll go over how to update our curriculum's web applications (i.e. projects, homework, assessments) and readings.

Goals

In updating the curriculum, all pull requests will be checked for the following:

General Behavior Should Not Change

Rails 5 brings a few brand-new technologies along with it. But the update we're making in-and-of-itself won't add any utilization of these technologies to our curriculum. In the future, we could add some readings on ActionCable, ActiveJob, and/or api_mode, but let's leave those for the future. It might even be possible to integrate some of these technologies into our projects at a later date.

As always, make sure that your updates don't introduce bugs. If your designated project updates happen to come with specs, use them. Whether or not your projects come with specs, manually test every bit of functionality!

Readings And Instructions Should Align With Student Experience

What students read in the instructions should align with their experiences. Let me give you an example of this not being the case. One project currently mentions that a blank controller action without a corresponding view should raise a Missing template error. While that is the case in Rails 4, the default response in such a situation in Rails 5 is instead head :no_content. This was a source of confusion for the majority of students, and it also took the TA's a while to pinpoint this new behavior. Let's avoid this.

For projects, please read and compare all responses and logs with any that are mentioned in the instructions.

For readings and quizzes, please ensure that all of the code blocks and quotations accurately reflect how Rails 5 actually behaves.

Speed

This update is a massive overhaul, and we want to get it through quickly. The longer we take to merge this update, the more time we'll spend merging in concurrent updates to the curriculum. To avoid treading water, we'll aim to move quickly. We should be able to finish this before the next SF cohort begins using Rails (August 17, 2017).

Please keep this in mind when working on your assignments!

Workflow

The update-rails branch will be the primary branch for this update. However, each update assignment will likely be quite large. For this reason, you should branch off of update-rails for your assignments.

To make the tracking of everyone's progress easier, all sub-branch names should be prefixed with update-rails. For instance, if you happen to be assigned to update the readings and homework of w4d4, create a new branch titled update-rails-w4d4. If you happen to be assigned the updating of a project, say Movie Buff, you should create a new branch called update-rails-movie-buff.

Once you finish up your work, please make a pull request where update-rails is the base and your branch is the compare.

Please avoid merge conflicts with other peoples' updates.

How To Update Things

What follows is a description of what I've experienced updating our projects and readings.

Updating A Rails Application

Gemfile

Replace the Rails entry with this:

gem 'rails', '~> 5.1.2'

Then, run:

bundle update rails

Rails Update Script

Run the following:

rails app:update

Recreate The Schema

There are some changes to schema.rb. Unique indexes are now in the create_table methods. Run the following:

rails db:migrate

rake -> rails

Rake tasks are now runnable via rails. Please replace rake with rails.

ApplicationRecord

Before Rails 5.x, all models inherited directly from ActiveRecord::Base. In Rails 5, all models inherit from ApplicationRecord.

This means that you need to create a new file in your /models folder by the name of application_record.rb:

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
end

Relations

Automatic belongs_to Validation

In Rails 5, all belongs_to relations are required and validated. If you happen to come across a belongs_to relationship that should be optional, please add optional: true and ensure that the corresponding instructions explain this behavior.

Association Ordering

In Rails 5, has_many_through relations must come after the has_many or belongs_to relations that they utilize. This seems like an unlikely issue with the current curriculum, but keep an eye out.

RSpec

params

For controller tests, be sure to wrap action request parameters in params.

For instance:

get :show, id: 1

should become this:

get :show, params: { id: 1 }

Updating Readings

Ensure that all of the things mentioned in the above section are represented, when relevant, in the readings.

If you happen to find typos or explanations that could be improved, feel free to change them. This is a good opportunity to make our curriculum is easier to read.

When updating quizzes, please ensure that any referenced logs/responses are exactly what Rails 5 produces.

rake -> rails

Rake tasks are now runnable via rails. Please replace rake with rails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment