LoginSignup
1
4

More than 5 years have passed since last update.

Rails4.2 -> Rails5.1.2 にアップグレードした際のメモ

Last updated at Posted at 2017-07-13

アップグレードガイドにあるものは割愛してます。

依存している gemの更新

bundle update rails

だとら埒があかないため、全部update

quiet_assets は取り込まれたので削除
http://docs.komagata.org/5348

migrationのバージョニング

migrationを作成したバージョンを付与すると最適に振る舞ってくれる

class CreateUsers < ActiveRecord::Migration[4.2]
end

面倒だったけど [4.2] を全部つけた。

attribute_wasがdeprecated

https://github.com/rails/rails/pull/25337#issuecomment-225166796
before と after それぞれのcallbackで値の意味が変わる(save,_createなど)
attribute_in_database は before だと変更前、 after
* だと変更後になる
わかりやすくなったが、メソッドの数が増えて複雑化している。

コントローラのテスト

getなどの引数
https://stackoverflow.com/questions/43797133/controller-spec-unknown-keyword-id
paramsが必須

post :create, params: { name: "hoge" }

一番面倒だった

ActiveSupport::MessageEncryptor

http://nisshiee.hatenablog.jp/entry/2017/04/17/192703
何も考えずにsecretに32バイト以上の文字列を入れていたら、 key must be 32 bytes と怒られた

APIドキュメントのようにKeyGeneratorを使う

ActiveRecord の uniqがdeprecated

http://qiita.com/zenpou/items/950432bae246063786e8#activerecord%E3%81%AEuniq-%E3%81%AF-distinct%E3%81%AB
uniqを呼び出すとArrayが返る。distinctを使う。
とっても怖い仕様変更。

Turbolinks5

ロード時の処理

turbolinks.load を使う
turbolinks-jquery は不要だったので外した

application.rb
$(document).on("turbolinks.load", function() {
});

data-turbolinks-track 属性

trueから"reload"にかえないとダメらしい。

application.html.erb
<%= javascript_include_tag "application", "data-turbolinks-track" => "reload" %>

プログレスバー

色変えただけ

.turbolinks-progress-bar {
  background-color: #f90;
}

AdminLTE

  $.AdminLTE.layout.fix();

migration

破壊防止措置らしい

bin/rails db:environment:set RAILS_ENV=development
bin/rails db:migrate:reset
1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4