2015/01/22分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
activemodel/CHANGELOG.md
- Support
:assigns
option when rendering with controllers/mailers. - Add ActionController::Renderer
- Add ActionController::Base.render
Fix test case class in the testing guide [ci skip]
rails guideのA Guide to Testing Rails Applications
の修正です。
ActiveJob
について説明している箇所で、exampleのテストの親クラスがActiveSupport::TestCase
になっていたのを、ActiveJob::TestCase
に修正しています。
Replace if exists
with table_exists?
and drop table statement with drop_table
activerecord/test/cases/migration/references_foreign_key_test.rb
、
activerecord/test/cases/primary_keys_test.rb
の修正です。
drop table if exists
を使用していた箇所をtable_exists?
メソッドでテーブルのチェックをするよう修正しています。
Oracleではdrop table if exists
が使用出来ない為修正しています。
Merge pull request #18322 from morgoth/add-error-codes
activemodel/lib/active_model/errors.rb
の修正です。
エラーが起きたvalidatorのtypeを取得出来るActiveModel::Errors#details
を追加しています。
class User < ActiveRecord::Base validates :name, presence: true end
user = User.new; user.valid?; user.errors.details # => {name: [{error: :blank}]}
複数エラーが起きても取得出来るようです。
class User < ActiveRecord::Base validates :name, presence: true validates :name, length: 1..30 end
user = User.new; user.valid?; user.errors.details => {:name=>[{:error=>:blank}, {:error=>:too_short, :count=>1}]}
Don't error when invalid json is assigned to a JSON column
activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
の修正です。
JSON型のカラムにJSONとして不正な値を設定した場合に、JSON::ParserError
が起きていたのを、エラーをrescueしてnilを設定するよう修正しています。
Add ActionController::Metal#set_request!
ここからコントローラのセットアップを簡略化するための対応のコミットが続きます。
まずはactionpack/lib/action_controller/metal.rb
の修正です。
ActionController::Metal#set_request!
メソッドを追加しています。
calling dispatch無しでコントローラのインスタンスにrequestを設定する為のメソッドです。
Support :assigns
option when rendering with controllers/mailers.
actionview/lib/action_view/rendering.rb
の修正です。
_render_template
メソッドに:assigns
オプションを追加しています。
render inline: '<%= @hello %>', assigns: { hello: "world" }
こんな使い方が出来るとの事。
Add ActionController#build_with_env
actionpack/lib/action_controller/metal/rack_delegation.rb
の修正です。
custom envで簡単にコントローラのインスタンスが生成出来るActionController#build_with_env
メソッドを追加しています。
Add ActionController::Renderer
コントローラアクション以外の箇所で任意のテンプレートをrenderする為のActionController::Renderer
クラスを新規に作成しています。
以下のようなフォーマットで使えます。
FooController.render :action, locals: { ... }, assigns: { ... }
Add ActionController::Base.render
actionpack/lib/action_controller/metal/rendering.rb
の修正です。
renderer
にアクセスする為のActionController::Base.render
メソッドを追加しています。
Add ApplicationController.renderer initializer [ci skip]
railties/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb
を新規に作成しています。
rendererのdefaults設定を記載する為のファイルで、サンプルは以下のような感じ。
## Change renderer defaults here. # # ApplicationController.renderer.defaults.merge!( # http_host: 'example.org', # https: false # )
ここでコントローラのセットアップを簡略化するための対応はおしまい。
use two spaces instead of one for include root in json
railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
の修正です。
exampleとして記載されているinclude_root_in_json
オプションのスペースが1つだったのを、他のオプションと合わせて2つに修正しています。
railties/lib/rails/application/configuration.rb
、
railties/lib/rails/engine.rb
の修正です。
assets
をRailsのconfigurationから削除しています。
sprockets-rails
の方で設定出来るようにした為、Rails本体からは削除したとの事です。
Add :formats to options list of render documentation.
rails guideのLayouts and Rendering in Rails
の修正です。
render
メソッドの:formats
オプションについての説明を追加しています。
Disable builds AR-JDBC against master
.travis.yml
の修正です。
JRubyのmasterブランチでactiverecord-jdbc-adapter
を使用するのを無効化しています。
activerecord-jdbc-adapter
がmasterブランチでビルド失敗するとの事です。詳細はこちら。
fix regexp for validate an integer in guides [ci skip]
rails guideのActive Record Validations
の修正です。
intgerチェック用の正規表現に誤りがあったのを修正しています。