Pairing Tour Day 5: Upgrading To The Asset Pipeline
I wrapped up last week by pairing with my mentor Mike on an upgrade to our 8th Light University app. It’s a straightforward Rails app that we needed to update to take care of the recently discovered Rails vulnerability. Mike also wanted to use it as an opportunity to make the jump up from Rails 3.0.10. That meant a leap to the asset pipeline and I wanted to document the steps we took in order to get everything working.
Update Rails and mySql
We have a pretty spartan Gemfile and use mySql2 so the only two things we needed to do to start were update the versions of these two gems:
gem 'rails', '~> 3.1.10'
gem ‘mysql2’, ‘0.3.11’
In the first run through of this upgrade we had some problems with mySql so I decided to lock it to version ‘0.3.11’. After this we did a
I’d never heard of
rake rails:update before but I came across it in this post after hitting some initial troubles and decided to give it a shot. What it does is goes through and updates your necessary files, but prompts you along the way so that you know what will be overwritten. Below is my terminal output as an example, which also includes what files I decided to overwrite and which I didn’t.
Whenever it prompted me to overwrite a file I loaded it in MacVim first, then allowed it to override, then selected ‘load file’ from the OS X dialog, then toggled between ‘undo’ (u) and ‘redo’ (r) to make sure I wanted to apply the changes:
Overwrite ~/projects/university/config/routes.rb? (enter "h" for help) [Ynaqdh] n
Overwrite ~/projects/university/config/application.rb? (enter "h" for help) [Ynaqdh] Y
Overwrite ~/projects/university/config/environments/development.rb? (enter "h" for help) [Ynaqdh] Y
Overwrite ~/projects/university/config/environments/production.rb? (enter "h" for help) [Ynaqdh] Y
Overwrite ~/projects/university/config/environments/test.rb? (enter "h" for help) [Ynaqdh] Y
Overwrite ~/projects/university/config/initializers/secret_token.rb? (enter "h" for help) [Ynaqdh] n
Overwrite ~/projects/university/config/initializers/session_store.rb? (enter "h" for help) [Ynaqdh] n
Overwrite ~/projects/university/config/locales/en.yml? (enter "h" for help) [Ynaqdh] Y
Moving the Assets & Creating Application files
app/assets/stylesheets. These three simple commands should do the trick (depending on the structure of your directories):
mv public/images app/assets/
mv public/stylesheets app/assets/
I also needed to add an application.js and application.css file that required my other files. The application.js file looked like this (note the order of the files you are requiring!):
//= require jquery
//= require jquery_ujs
//= require_tree .
and the application.css file looked like this (again, pay attention to order!):
*= require reset
*= require_tree .
Add the Asset Gems
Next, add this group to your Gemfile, followed by a
bundle update command:
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', " ~> 3.1.0"
gem 'uglifier', '1.0.4'
Changing the config files:
Update or add the following lines in their corresponding files:
config.action_view.debug_rjs = true
config.serve_static_assets = true
Update your views and CSS
img src="public/assets/gangnam-style.gif"tag— but now we use an image tag like
. You’ll have to go in and change each of these image links manually.
We also need to update the headers of our
’layout.html.erb’ file to include our new
application.css files. The old links probably looked something like:
<%= stylesheet_link_tag 'reset.css', 'jquery.css', '8thlightu.css' %>
which can be replaced with:
<%= stylesheet_link_tag 'application.css’ %>
Jasmine YML Update
At this point all of our RSpec and Cucumber tests were passing (and things looked good when we fired up our server) but none of our Jasmine specs passed. We realized that our
with these two lines:
If everything went according to plan then congrats, you’re done! Things should look great and all of your Specs, Features and Jasmine Tests pass… Of course, I realize that may not be the case and there might be a hiccup or two along the way. If anyone has experience with alternate upgrade paths, questions, or feedback I’d love to hear it.