私は本当にこれを理解することができないので、私はただこれをそこに投げています。たとえば、呼び出すとuser.articles.create! { title: 'blah' }
nilが返されますが、オブジェクトは作成されます。私はこれまでこのようなものを見たことがなく、他の誰かが持っているかどうか疑問に思っていましたか?
Rails 3.2.13と3.2.12を試しましたが、どちらも同じことをします。
編集
アクティブレコードでは、作成と作成の両方を行います。レコードを返すか、例外をスローすることになっているこのメソッドで終了します。
def create_record(attributes, options, raise = false, &block)
unless owner.persisted?
raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
end
if attributes.is_a?(Array)
attributes.collect { |attr| create_record(attr, options, raise, &block) }
else
transaction do
add_to_target(build_record(attributes, options)) do |record|
yield(record) if block_given?
insert_record(record, true, raise)
end
end
end
end