なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2017/04/28)

2017/04/28分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

actionview/CHANGELOG.md


Add documentation of data attributes for UJS [ci skip]

rails guideのWorking with JavaScript in Railsの修正です。

rails-ujsでのdata attributes(data-methoddata-disable-with等)の指定の方法や扱われか方等についての説明を追加しています。


Evaluate belongs_to :default option against the owner, not the association

activerecord/lib/active_record/associations/belongs_to_association.rbの修正です。

belongs_todefaultオプションに指定したblockを実行する際、associationに対して実行していたのを、associationが定義されているmodelの元で実行するよう修正しています。

PRより。

# app/models/ship.rb
class Ship < ApplicationRecord
  belongs_to :developer, default: -> { default_developer }

  def default_developer
    Developer.first
  end
end

というクラスがあった場合に、

# before
ship = Ship.create!
NameError: undefined local variable or method `default_developer' for #<ActiveRecord::Associations::BelongsToAssociation:0x0056312d94b8d0>

# after
ship = Ship.create!
# => #<Ship id: 1, developer_id: 1>

のように、modelで定義したメソッドが呼べるようになっています。


Also raise error when VERSION is nil

activerecord/lib/active_record/railties/databases.rakeの修正です。

VERSION envを指定せずにdb:migrate:updb:migrate:downを実行してもエラーにならないバグがあったのを修正しています。


Ensure input to distance_of_time_in_words is not nil

actionview/lib/action_view/helpers/date_helper.rbの修正です。

distance_of_time_in_wordsメソッドの引数に不正な値(nil等)を指定した場合のエラーメッセージの改善、及び、from_timeto_time引数にTime / Date objectとNumericが混在した場合に正常に動作するよう修正しています。

# before

helper.time_ago_in_words(nil)
# => NoMethodError: undefined method `>' for nil:NilClass

helper.distance_of_time_in_words(Date.current, 0)
# => NoMethodError: undefined method `/' for 2017-04-28 00:00:00 +0900:Time


# after

helper.time_ago_in_words(nil)
# => ArgumentError: nil can't be converted to a Time value

helper.distance_of_time_in_words(Date.current, 0)
# => "over 47 years"

Merge pull request #28844 from kyuden/remove_unnecessary_attributes_of_select_in_form_with

actionview/lib/action_view/helpers/tags/base.rbの修正です。

form_withが生成するformの中でselectタグを生成する際に、不要なskip_default_idsallow_method_names_outside_object attributesが付与されてしまっていたのを、付与されないよう修正しています。


Added some more release notes for Active Record [ci skip]

rails guideのRuby on Rails 5.1 Release Notesの修正です。

Active Recordの項にエントリーを追加しています。


Fix indentation [ci skip]

rails guideのRuby on Rails 5.1 Release Notesの修正です。

Active Recordの項のエントリーのインデントがずれていたのを調整しています。


Small grammar fixes

rails guideのWorking with JavaScript in Railsの修正です。

グラマーの修正を行っています。


Small grammar fix

rails guideのRuby on Rails 5.1 Release Notesの修正です。

グラマーの修正を行っています。


5.1 Release Notes are complete [ci skip]

guides/source/documents.yamlの修正です。

Ruby on Rails 5.1 Release NotesからWIPを削除し、リリースしています。