The buzz cut

Ramblings from the barbershop

Upgrading to Rails4: Encrypted Cookies, Observers, Et Al.

| Comments

The ‘activerecord-session_store’ gem provides support for those storing sessions in the database. My app stores sessions in cookies, so I removed that gem from my Gemfile. That said, Rails 4 introduces an encrypted cookie store, which I want to use. The first thing I had to do was edit config/initializers/session_store.rb and change this:

1
2
3
4
Screencast::Application.config.session_store
  :cookie_store,
  key: '_screencast_session',
  domain: :all

To this:

1
2
3
4
Screencast::Application.config.session_store
  :upgrade_signature_to_encryption_cookie_store,
  key: '_screencast_session',
  domain: :all

Then I ran:

1
2
$ rake secret
xxxyyy1234...

Finally, I edited config/intializers/secret_token.rb and added a config for secret_key_base, using the hash that I had just generated. Note, leave the secret_token config alone.

1
2
Screencast::Application.config.secret_token = '111222333leavemealone'
Screencast::Application.config.secret_key_base = 'xxxyyy1234...'

Another one down! We’re in the home stretch as the rest of the backward compatability gems you’re probably not using.

The ‘rails-observers’ gem allows Rails 4 apps to still use Observers, which have been phased out. I don’t use observers in this app, so I can safely remove this gem. For those using observers, the recommendation is to move your observed code into model callbacks (i.e., after_save)

Next up was the ‘actionview-encoded_mail_to’ gem. This provides backward compatability for those who used the “encode” option when using the “mail_to” helper. I never did that, and I bet you didn’t either, which is why the functionality was removed from Rails 4 and extracted to this gem. Remove the gem — another one down!

Next up was the ‘rails-perftest’ gem. Performance tests were removed from Rails 4 and extracted to this gem. If you don’t need them, you don’t need this gem. Remove it and move on. Another one down!

Finally, the ‘actionpack-xml_parser’ gem simply extracted XML parsing into its own gem. Again, my app didn’t need this, so I removed the gem.

Woo! All backward compatability gems have been addressed. I’ve converted all of my code and have removed all of them, including the ‘rails4_upgrade’ gem.

That’s it. I’m officially running a Rail4 upgraded app!

Comments