rake rails:updateした時のRails3.2とRails4.0の変更点

- Rails 3.2.22⇒Rails 4.0.13へバージョンアップした際、rake rails:updateでコンフリクトするファイル、内容のまとめ。Rubyは2.2.3 調べながらなので間違ってたらご指摘ください。

-  config/boot.rb
 - require 'rubygems'が無くなった
 -  File.exists?がFile.exist?になった。[deprecatedらしい](http://docs.ruby-lang.org/ja/search/query:exists%3F/)

```config/boot.rb
- require 'rubygems'
-
  # Set up gems listed in the Gemfile.
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
```

-  config/routes.rb
 - コメントが変わってるだけ。マージは必要なし？ match直す必要あり

```config/routes.diff
-Clean32::Application.routes.draw do
-  # The priority is based upon order of creation:
-  # first created -> highest priority.
-
-  # Sample of regular route:
-  #   match 'products/:id' => 'catalog#view'
-  # Keep in mind you can assign values other than :controller and :action
-
-  # Sample of named route:
-  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
-  # This route can be invoked with purchase_url(:id => product.id)
+Clean40::Application.routes.draw do
+  # The priority is based upon order of creation: first created -> highest priority.
+  # See how all your routes lay out with "rake routes".

-  # Sample resource route (maps HTTP verbs to controller actions automatically):
+  # You can have the root of your site routed with "root"
+  # root 'welcome#index'
+
+  # Example of regular route:
+  #   get 'products/:id' => 'catalog#view'
+
+  # Example of named route that can be invoked with purchase_url(id: product.id)
+  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
+
+  # Example resource route (maps HTTP verbs to controller actions automatically):
   #   resources :products

-  # Sample resource route with options:
+  # Example resource route with options:
   #   resources :products do
   #     member do
   #       get 'short'
@@ -25,34 +26,31 @@
   #     end
   #   end

-  # Sample resource route with sub-resources:
+  # Example resource route with sub-resources:
   #   resources :products do
   #     resources :comments, :sales
   #     resource :seller
   #   end

-  # Sample resource route with more complex sub-resources
+  # Example resource route with more complex sub-resources:
   #   resources :products do
   #     resources :comments
   #     resources :sales do
-  #       get 'recent', :on => :collection
+  #       get 'recent', on: :collection
   #     end
   #   end

-  # Sample resource route within a namespace:
+  # Example resource route with concerns:
+  #   concern :toggleable do
+  #     post 'toggle'
+  #   end
+  #   resources :posts, concerns: :toggleable
+  #   resources :photos, concerns: :toggleable
+
+  # Example resource route within a namespace:
   #   namespace :admin do
   #     # Directs /admin/products/* to Admin::ProductsController
   #     # (app/controllers/admin/products_controller.rb)
   #     resources :products
   #   end
-
-  # You can have the root of your site routed with "root"
-  # just remember to delete public/index.html.
-  # root :to => 'welcome#index'
-
-  # See how all your routes lay out with "rake routes"
-
-  # This is a legacy wild controller route that's not recommended for RESTful applications.
-  # Note: This route will make all actions in every controller accessible via GET requests.
-  # match ':controller(/:action(/:id))(.:format)'
 end
```
- config/application.rb
 - if defined?が無くなった。Bundler.requireだけ残ってる。

```config/application.rb
if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end
↓
Bundler.require(:default, Rails.env)#これに変えれる
```
- 設定が色々無くなっている。残しといていいのかな？
 -  config.encoding アプリケーション全体のエンコーディングの設定
 -  config.filter_parameters += [:password] パスワードやクレジットカード番号のような、 ログに表示させたくないパラメータをフィルタリングするのに使用
 -  config.active_support.escape_html_entities_in_json JSONシリアライズ内のHTMLエンティティのエスケープの有効・無効を設定
 -  config.active_record.whitelist_attributes Rails4から[基本機能なのでいらない？](http://blog.willnet.in/entry/2012/10/26/005901)
 -  config.assets.enabled アセットパイプライン(asset pipeline)の有効/無効を制御
 -  config.assets.version MD5ハッシュ生成に使用される任意の文字列

```config/application.rb
    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    # Enable escaping HTML in JSON.
    config.active_support.escape_html_entities_in_json = true

    # Use SQL instead of Active Record's schema dumper when creating the database.
    # This is necessary if your schema can't be completely dumped by the schema dumper,
    # like if you have constraints or database-specific column types
    # config.active_record.schema_format = :sql

    # Enforce whitelist mode for mass assignment.
    # This will create an empty whitelist of attributes available for mass-assignment for all models
    # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
    # parameters by using an attr_accessible or attr_protected declaration.
    config.active_record.whitelist_attributes = true

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
```

-  config/environment.rb コメントだけ

```config/environment.diff
- # Load the rails application
+ # Load the Rails application.
  require File.expand_path('../application', __FILE__)

- # Initialize the rails application
+ # Initialize the Rails application.
  AppSpace::Application.initialize!
```

- config/environments/development.rb
 - config.whiny_nils 初期化されていないオブジェクトが呼び出させたときに、警告を表示 [削除する](http://ariiyu.hatenablog.com/entry/2013/11/22/220854)
 - config.eager_load Rails のモデルやコントローラーであるクラスをブート時に全て読み込むかどうか
 - config.action_dispatch.best_standards_support　mass assingment対策更新対象カラムに含まれていた場合、例外が発生。削除する
 - config.active_record.auto_explain_threshold_in_seconds　スロークエリを自動的にロギングする。削除する
 - config.assets.compress css,javascriptを圧縮する。Rails4では使えない。削除する
 - config.active_record.migration_errorマイグレーションが最新でない場合にページを開く時に例外が出る。コメントアウトしておく？

```config/environments/development.diff
-  # Log error messages when you accidentally call methods on nil.
-  config.whiny_nils = true
+  # Do not eager load code on boot.
+  config.eager_load = false
-  # Only use best-standards-support built into browsers
-  config.action_dispatch.best_standards_support = :builtin
-  # Raise exception on mass assignment protection for Active Record models
-  config.active_record.mass_assignment_sanitizer = :strict
+  # Raise an error on page load if there are pending migrations
+  config.active_record.migration_error = :page_load
-  # Log the query plan for queries taking more than this (works
-  # with SQLite, MySQL, and PostgreSQL)
-  config.active_record.auto_explain_threshold_in_seconds = 0.5

-  # Do not compress assets
-  config.assets.compress = false
```

- config/environments/production.rb
 - config.assets.js_compressor JavaScriptの圧縮方式uglifier
 - config.assets.css_compressor　cssの圧縮こちらも有効にする？
 - config.assets.version = Assetのバージョンを指定
 - config.log_level　ログレベルの指定デフォルトはinfo検討必要
 - config.log_formatter　Railsロガーのフォーマットを定義

```config/environments/production.diff
+  config.eager_load = true
+
-  # Compress JavaScripts and CSS
-  config.assets.compress = true
+  # Compress JavaScripts and CSS.
+  config.assets.js_compressor = :uglifier
+  # config.assets.css_compressor = :sass

-  # Defaults to nil and saved in location specified by config.assets.prefix
-  # config.assets.manifest = YOUR_PATH
+  # Version of your assets, change this if you want to expire all your assets.
+  config.assets.version = '1.0'

-  # See everything in the log (default is :info)
-  # config.log_level = :debug
+  # Set to :debug to see everything in the log.
+  config.log_level = :info

+  # Use default logging formatter so that PID and timestamp are not suppressed.
+  config.log_formatter = ::Logger::Formatter.new

```

- config/initializers/inflections.rb
 - コメントが変わっている。そのまま上書きでOKでは

```config/initializers/inflections.diff
- # Add new inflection rules using the following format
+ # Add new inflection rules using the following format. Inflections
- # (all these examples are active by default):
+ # are locale specific, and you may define rules for as many different
- # ActiveSupport::Inflector.inflections do |inflect|
+ # locales as you wish. All of these examples are active by default:
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
  #   inflect.plural /^(ox)$/i, '\1en'
  #   inflect.singular /^(ox)en/i, '\1'
  #   inflect.irregular 'person', 'people'
  #   inflect.uncountable %w( fish sheep )
  # end
- #
+
  # These inflection rules are supported but not enabled by default:
- # ActiveSupport::Inflector.inflections do |inflect|
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
  #   inflect.acronym 'RESTful'
  # end
```

- config/initializers/secret_token.rb
 - メソッド、キーが変わってる。取り敢えずそのままにする？[Rails4.1では無くなってymlになってる](http://railsguides.jp/upgrading_ruby_on_rails.html)

```config/initializers/secret_token.diff
-Clean32::Application.config.secret_token = 'e～～～～'
+Clean40::Application.config.secret_key_base = 'd～～～～～～'
```
- config/initializers/session_store.rb
 - コメント消えただけ？
 
```config/initializers/session_store.diff
-Clean32::Application.config.session_store :cookie_store, key: '_clean3.2_session'
-
-# Use the database for sessions instead of the cookie-based default,
-# which shouldn't be used to store highly confidential information
-# (create the session table with "rails generate session_migration")
-# Clean32::Application.config.session_store :active_record_store
+Clean40::Application.config.session_store :cookie_store, key: '_clean4_0_session'
```

- config/initializers/wrap_parameters.rb
 - wrap_parameters [JSONをRailsへ送った時にルート要素を省いて送れる。](http://katahirado.hatenablog.com/entry/2014/08/26/210247)
 - include_root_in_json JSONのルート要素をデフォルトで有効に

```config/initializers/wrap_parameters.diff
-#
+
 # This file contains settings for ActionController::ParamsWrapper which
 # is enabled by default.

 # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
 ActiveSupport.on_load(:action_controller) do
-  wrap_parameters format: [:json]
+  wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
 end

-# Disable root element in JSON by default.
-ActiveSupport.on_load(:active_record) do
-  self.include_root_in_json = false
-end
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+#  self.include_root_in_json = true
+# end
```

- config/locales/en.yml
 - コメント増えてる。上書きOK 

```config/locales/en.diff
- # Sample localization file for English. Add more files in this directory for other locales.
+ # Files in the config/locales directory are used for internationalization
- # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+ # and are automatically loaded by Rails. If you want to use locales other
+ # than English, add the necessary files in this directory.
+ #
+ # To use the locales, use `I18n.t`:
+ #
+ #     I18n.t 'hello'
+ #
+ # In views, this is aliased to just `t`:
+ #
+ #     <%= t('hello') %>
+ #
+ # To use a different locale, set it with `I18n.locale`:
+ #
+ #     I18n.locale = :es
+ #
+ # This would use the information in config/locales/es.yml.
+ #
+ # To learn more, please read the Rails Internationalization guide
+ # available at http://guides.rubyonrails.org/i18n.html.
```