ActiveRecord::Base::transaction() do ~ end 間でreturnしてもロールバックされない。 ロールバックするには、例外をスローする必要がある。 以下に例を示します。 @studentの登録に成功し、@profileの登録に失敗した場合。 ○@studentの登録がロールバックされる begin ActiveRecord::Base::transaction() do @student = Student::create(params[:student]) @profile = @student.create_profile(params[:profile]) unless @student.errors.empty? raise ActiveRecord::RecordInvalid::new(@student) end unless @profil