#author("2017-05-01T15:34:28+09:00","default:wikiwriter","wikiwriter") &tag(Rails/アップグレード); *目次 [#i7b29fc5] #contents *関連ページ [#ka78e350] *参考情報 [#b73bc7b2] -[[Rails アップグレードガイド | Rails ガイド:https://railsguides.jp/upgrading_ruby_on_rails.html]] -[[Rails 5へのアップグレード手順メモ(Rails 4.2.6 => 5.0.0) - Qiita:http://qiita.com/ryo511/items/2a387df126268fec8c78]] -[[ダメ男のブログ: 【Rails5.0.0】 rails4.2.5からrails5.0.0にアップグレードする その1 Gemと設定ファイルの修正:http://edywrite.blogspot.jp/2016/07/rails500-rails425rails500-1-gem.html]] -[[ダメ男のブログ: 【Rails5.0.0】 Rails4.2.5からRails5.0.0へのアップグレードでバッチが動かなくなった:http://edywrite.blogspot.jp/2016/07/rails500-rails425rails500.html]] *Rails 4.2からRails 5.0 [#kae9c16c] **手順 [#s9cb922d] -GemfileのRailsバージョンをRails.5.0系の最新版に書き換えてbundle updateを実行。 bundle update -設定ファイルの更新。古い設定ファイルを上書きしようとしてくるので基本Yesで応える。後からgit diffで差分を見ながら移植したほうがよさげ。 bundle exec rails app:update -IntelliJの場合Compare with Branchで比較する(Commitだと変更を戻したりできない)。routes.rbなど適宜commitしたバージョンを戻していく。 -app/models/application_record.rbを作成 #pre{{ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end }} -各モデルクラスが継承するようにする(必須ではない)。 #pre{{ class Book < ApplicationRecord end }} **移行後のWarningつぶし [#ye6eeaa1] -デバッグ実行 or テストを実行してWarningをつぶしていく ***MySQLの絵文字 [#ib17db7f] -MySQLで絵文字を使っている場合はar_innodb_row_format.rbの書き換えが必要。 ***before_filter is deprecated [#o702369a] -before_actionに書き換える。 ***Rails Controller Testingのエラー [#oe8e550f] -controllerのテストでassignを使っている場合以下のようなエラーが表示される #pre{{ NoMethodError: assigns has been extracted to a gem. To continue using it, add `gem 'rails-controller-testing'` to your Gemfile. }} -Gemfileにrails-controller-testingを追加する #pre{{ group :test do gem "rails-controller-testing" end }} -.DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated, -以下のようなエラー。 #pre{{ .DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated, in favor of keyword arguments, and will be removed in Rails 5.1. Deprecated style: get :show, { id: 1 }, nil, { notice: "This is a flash message" } New keyword style: get :show, params: { id: 1 }, flash: { notice: "This is a flash message" }, session: nil # Can safely be omitted. }} -指示通りにparamsやflashなどのキーワードを追加すうr。 #pre{{ post :create, params: {book: { author: @book.author, summary: @book.summary, title: @book.title }} get :show, params: {id: @book} }}