Rails 1.2.3 〜 2.2.2 までの主な変更点のまとめ

rails の2.x 系をまともに勉強していなかったので、調査しました。コピペの部分も多いですが、情報ソースと共に記述します。
あまり変更点がなかったマイナーアップデートは除外してあります。

1.2.4

  • 2.0 からエラーになる構文に対する警告出力
    • 1.2.4 で警告がでなければ、2.0 で問題なく動くと言われている
  • セッション固定攻撃対策として, URLベースセッションのサポートを削除
  • ActiveRecord::Base#to_jsonを使っている場合に発生する可能性があるXSS攻撃を回避するようにJSONエンコーディングアルゴリズムが変更

1.2.6

  • 1.2 系最終リリース
  • セッションIDの固定化の脆弱性修正

2.0.1

  • 公開されたバージョンは2.0.1とされている。これはリリース直後に問題が発覚したため修正版が公開されたため
  • 組み込みデバッガ
    • ruby-debug ベースのデバッガが使えるように
    • script/server -u で起動すると使えるようになる
    • テストでも使用可能
  • RESTful 機能ベースへ
    • SOAP からREST へ
  • actionwebservice 廃止、activeresource
  • ルーテシングへの名前空間の導入。名前付きルートが使用できるように
    • 設定したものはrake routes で使用可能に
  • コントローラ名を複数系にする規約を推進
    • これによって、単独のリソースが複数のコンテキスト内でマッピング可能でありながらも同じコントローラを参照することができる
  • テンプレート用フォーマットの変更
    • action.format.renderer
    • show.html.erb はshow アクションの結果呼ばれ、HTML を返す。レンダラにはERB を使用する(今までのshow.rhtml)
  • Accept ヘッダに対するrespond_to メソッドの応答
    • index.atom.builder: 以前はrxmlとして知られたBuilderフォーマットを使用して、application/atom+xmlというMIMEタイプに対してindexアクションをレンダリング
    • リクエストのAccept ヘッダと一致する1つ目のレスポンダメソッドが呼び出される
    • リクエストのデータ形式を適切に変換することで、action メソッドは同じ状態がたもてる
      • 1. HTTP/1.1 リクエストヘッダ中の Accept フィールドを見る
      • 2. content-type に応じてリクエストのデータ形式を自動変換してくれる
      • 3. 従って、コントローラは同じロジック(action)で対応できる
      • 4. Accept の種類(mimeタイプ)に応じて、実行する描画処理を指定できる
    • Accept ヘッダを送信しないブラウザでも、.xml などの拡張子をURL で指定することにより、それに対応するフォーマットのレスポンスダメソッドが呼び出される
    • edit.iphone.haml みたいなカスタムも定義可能。MIME TYPE のiphoneiPhone専用の特別なHTMLインターフェースを利用したいときなどに有効
  • BASIC 認証モジュール追加。SSLAPI 認証を行う場合などに使うという想定
  • 論理ユニット内でJavaScriptスタイルシートファイルがはるかに簡単に構築できる
    • hoge.css, fuga.css, fib.js のように大量のファイルをリクエストしなくていい
    • javascript_include_tag(:all, :cache => true)を使用すると、稼動中はpublic/javascripts/.jsを単独のpublic/javascripts/all.jsファイルに変換しながらも開発中はファイルを別々に保つため、キャッシュをクリアせずに繰り返し作業を行うことができる
  • 静的ファイルの提供元を別サーバに向けるasset_host
  • CSRF 対策
  • XSS 対策
  • コントローラレベルでの例外処理方法機能の追加
    • rescue_action_in_publicを上書きする以外に、rescue_from User::NotAuthorized, :with => :deny_access という風に書けるようになった
  • デフォルトのセッション保存先が、Cookie
    • 偽造が不可能なハッシュ形式として保存
    • セッション情報をサーバ側に保存しなくていい
    • cron でセッションデータを消す必要がなくなる
  • リクエストプロファイラの追加
    • HTMLおよびテキスト内でどこに時間を費やしたかについて完全な内訳が得られる
  • AtomFeedHelper によるFeed 生成の簡単化
  • シンプルなQuery Cacheの追加
    • 同様のSQLコールを同じリクエスト内から認識し、キャッシュした結果を返すというもの
  • Migration の記述に別フォーマットを用意
    • t.column :hoge, :integer => t.integer :hoge
  • id なしでフィクスチャを使えるようになった
    • 個人的にはDB の実際の内容とずれるので嫌い
# sellers.yml
shopify:
name: Shopify

# products.yml
pimp_cup:
seller: shopify
name: Pimp cup
  • AR::Base#to_jsonJSON 形式でシリアライズできるようになった
  • Person.new.from_xml(“David“) のようにしてXML からアンシリアライズできるようになった
  • AR のスリム化
  • AR::Base.with_scope をprotected に
    • コントローラ内(時にフィルタ内)で誤って使用されることを阻止するため
    • モデル自身の中でのみ使用することが推奨されます。それこそが設計目的であり、論理的に適合している
    • もし使う場合はsend 経由で使用
  • config/initializers 導入
    • environment.rb によって環境が設定された後に実行されるファイル群を置ける
    • 初期化時の設定をこのファイルに定義する

2.0.2

  • デフォルトのDB がsqlite3 に
  • 「config.action_view.cache_template_loading = true」が設定されるように変更された。この変更で頻繁に実施されていたディスクアクセスが抑制される

2.1.0

  • named_scope
  • UTC-based Migration
  • タイムゾーン設定を行えるようになりました
  • ARオブジェクトの状態(変更されてるかどうか)を確認できる機能が追加になりました(Dirty Tracking)
  • ARでの更新の際、余計なSQL文を吐かなくなりました(Partial Update)
  • ビューキャッシュ機能の改善
    • キャッシュストアとしてmemcached, druby などが使えるようになった
  • 依存gemを/vendor/gems以下に配置することができるようになりました
    • config/environments.rbでのconfig.gem gem_name で宣言。バージョンも指定可能
    • rake gems:installで足りないgemをinstallします。
    • rake gems:unpackで、必要なgemを/vendor/gems以下にコピーします

2.1.1

  • functional test中のfollow_redirecが非推奨に。リダイレクトのテストにはintegration testを使用してください
  • Migration のファイルフォーマットがUTC ベースと連番が選択可能に
  • Rails.envをStringInquirerでラップして返すようにしたので、 Rails.env.development?のようなものが使えるようになりました。

2.2.0

  • i18n サポート
  • HTTPヘッダのETagとLast-Modifiedのサポートにより、変更のないリソースへのリクエストでは空のレスポンスを返すことができます
  • Transactional Migration(PostgreSQLのみサポート)
  • コネクションプーリングにより、Railsはコネクションプールを通じてデータベースリクエストを行います。(コネクション数の上限はdefaultで5。database.ymlで:poolを追加することにより設定可能)これにより複数同時実行ユーザがいる場合のボトルネックを解消します
  • find_last_by_(Model.last(:conditions => { :attribute => value })と同義です)
  • find_by_!
  • ActionMailerはレイアウトをサポートするようになりました
  • ActiveSupport::Rescuableを使えば、どんなクラスでもrescue_fromが使えます
  • Date,Timeクラスに、past?, today?, future?が追加され、日付の比較が簡単になりました
  • config.gems の強化
    • gemの複雑な依存関係を操り、さらに柔軟で強固なものになっています
    • rake gems:unpack:dependenciesで、必要なgemと、それらの依存gemを/vendor/gems以下にコピーします
  • script/serverがThin をサポート
  • render :partialを使用する場合の暗黙のローカル変数割り当ては非推奨に
    • 部分テンプレートと同じ変数名で、その名前のインスタンス変数を参照できるやつ
  • ActiveRecord::Errors.default_error_messagesはI18n.translate(activerecord.errors.messages)のがあるため非推奨に
  • Ruby on Rails Guides でドキュメントを提供開始
  • MySQL のアダプタもgem 化

その他

rails 2.2.2 のrake タスク一覧
(in /Users/luke/apps/rails/demo2_2_2)
rake db:abort_if_pending_migrations  # Raises an error if there are pending migrations
rake db:charset                      # Retrieves the charset for the current environment's database
rake db:collation                    # Retrieves the collation for the current environment's database
rake db:create                       # Create the database defined in config/database.yml for the current RAILS_ENV
rake db:create:all                   # Create all the local databases defined in config/database.yml
rake db:drop                         # Drops the database for the current RAILS_ENV
rake db:drop:all                     # Drops all the local databases defined in config/database.yml
rake db:fixtures:identify            # Search for a fixture given a LABEL or ID.
rake db:fixtures:load                # Load fixtures into the current environment's database.
rake db:migrate                      # Migrate the database through scripts in db/migrate.
rake db:migrate:down                 # Runs the "down" for a given migration VERSION.
rake db:migrate:redo                 # Rollbacks the database one migration and re migrate up.
rake db:migrate:reset                # Resets your database using your migrations for the current environment
rake db:migrate:up                   # Runs the "up" for a given migration VERSION.
rake db:reset                        # Drops and recreates the database from db/schema.rb for the current environment.
rake db:rollback                     # Rolls the schema back to the previous version.
rake db:schema:dump                  # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load                  # Load a schema.rb file into the database
rake db:sessions:clear               # Clear the sessions table
rake db:sessions:create              # Creates a sessions migration for use with CGI::Session::ActiveRecordStore
rake db:structure:dump               # Dump the database structure to a SQL file
rake db:test:clone                   # Recreate the test database from the current environment's database schema
rake db:test:clone_structure         # Recreate the test databases from the development structure
rake db:test:load                    # Recreate the test database from the current schema.rb
rake db:test:prepare                 # Check for pending migrations and load the test schema
rake db:test:purge                   # Empty the test database
rake db:version                      # Retrieves the current schema version number
rake doc:app                         # Build the app HTML Files
rake doc:clobber_app                 # Remove rdoc products
rake doc:clobber_plugins             # Remove plugin documentation
rake doc:clobber_rails               # Remove rdoc products
rake doc:guides                      # Generate Rails guides
rake doc:plugins                     # Generate documentation for all installed plugins
rake doc:rails                       # Build the rails HTML Files
rake doc:reapp                       # Force a rebuild of the RDOC files
rake doc:rerails                     # Force a rebuild of the RDOC files
rake gems                            # List the gems that this rails application depends on
rake gems:build                      # Build any native extensions for unpacked gems
rake gems:install                    # Installs all required gems for this application.
rake gems:refresh_specs              # Regenerate gem specifications in correct format.
rake gems:unpack                     # Unpacks the specified gem into vendor/gems.
rake gems:unpack:dependencies        # Unpacks the specified gems and its dependencies into vendor/gems
rake log:clear                       # Truncates all *.log files in log/ to zero bytes
rake notes                           # Enumerate all annotations
rake notes:custom                    # Enumerate a custom annotation, specify with ANNOTATION=WTFHAX
rake notes:fixme                     # Enumerate all FIXME annotations
rake notes:optimize                  # Enumerate all OPTIMIZE annotations
rake notes:todo                      # Enumerate all TODO annotations
rake rails:freeze:edge               # Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0
rake rails:freeze:gems               # Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze                  # Unlock this application from freeze of gems or edge and return to a fluid use of system gems
rake rails:update                    # Update both configs, scripts and public/javascripts from Rails
rake rails:update:configs            # Update config/boot.rb from your current rails install
rake rails:update:javascripts        # Update your javascripts from your current rails install
rake rails:update:scripts            # Add new scripts to the application script/ directory
rake routes                          # Print out all defined routes in match order, with names.
rake secret                          # Generate a crytographically secure secret key.
rake stats                           # Report code statistics (KLOCs, etc) from the application
rake test                            # Run all unit, functional and integration tests
rake test:benchmark                  # Run tests for benchmarkdb:test:prepare / Benchmark the performance tests
rake test:functionals                # Run tests for functionalsdb:test:prepare / Run the functional tests in test/functional
rake test:integration                # Run tests for integrationdb:test:prepare / Run the integration tests in test/integration
rake test:plugins                    # Run tests for pluginsenvironment / Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)
rake test:profile                    # Run tests for profiledb:test:prepare / Profile the performance tests
rake test:recent                     # Run tests for recentdb:test:prepare / Test recent changes
rake test:uncommitted                # Run tests for uncommitteddb:test:prepare / Test changes since last checkin (only Subversion and Git)
rake test:units                      # Run tests for unitsdb:test:prepare / Run the unit tests in test/unit
rake time:zones:all                  # Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:local                # Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time
rake time:zones:us                   # Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset.
rake tmp:cache:clear                 # Clears all files and directories in tmp/cache
rake tmp:clear                       # Clear session, cache, and socket files from tmp/
rake tmp:create                      # Creates tmp directories for sessions, cache, and sockets
rake tmp:pids:clear                  # Clears all files in tmp/pids
rake tmp:sessions:clear              # Clears all files in tmp/sessions
rake tmp:sockets:clear               # Clears all files in tmp/sockets