The buzz cut

Ramblings from the barbershop

Upgrading to Rails4: Active_resource & Cache_digests

| Comments

Working my way down the list of backward-compatability gems, I came to to:

1
gem 'activddderesource', github: 'rails/activeresource'

This one was easy. I don’t use it, and it’s likely that you don’t either. I simply removed this gem from my Gemfile. Two down!

The next two gems were caching-related:

1
2
gem 'actionpack-action_caching', github: 'rails/actionpack-action_caching'
gem 'actionpack-page_caching', github: 'rails/actionpack-page_caching'

Rails 4 deprecated both page & action caching. Fragment caching is the preferred caching technique now, and fragment caching has even been improved with “Russion Doll” caching.

Luckily, my app wasn’t using any action or page caching, so I removed the action-caching and page-caching gems, but I did have some fragment caching that needed updating. This was easy enough as it’s just a matter of removing those pesky version numbers from cache blocks. Cache busting happens automagically now. So, I updated code like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# app/views/shows/show.html.erb
# app/views/shows/show.html.erb

<% cache ["v2", @show] do %>;
  <h1>;<%= @show.title %>;</h1>;
  ...
  <ul>;
    <%= render @show.episodes %>;
  </ul>;
  ...
<% end %>;

# app/views/shows/_episode.html.erb
<% cache ["v2", @episode] do %>;
  ...
  <li class="episode">;
    <%= @episode.title %>;
    ...
  </li>;
  ...
<% end %>;

To something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# app/views/shows/show.html.erb
<% cache @show do %>;
  <h1>;<%= @show.title %>;</h1>;
  ...
  <ul>;
    <%= render @show.episodes %>;
  </ul>;
  ...
<% end %>;

# app/views/shows/_episode.html.erb
<% cache @episode do %>;
  <li class="episode">;
    ...
    <%= @episode.title %>;
    ...
  </li>;
<% end %>;

Next up, tackling the remaining gems:

1
2
3
4
5
gem 'activerecord-session_store'
gem 'rails-observers'
gem 'actionview-encoded_mail_to'
gem 'rails-perftest'
gem 'actionpack-xml_parser', github: 'rails/actionpack-xml_parser'

Comments