Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
efd2410b
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
efd2410b
编写于
7月 21, 2015
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20967 from lxsameer/record_not_found
Extra caller details added to ActiveRecord::RecordNotFound
上级
b260a273
d763956e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
35 addition
and
5 deletion
+35
-5
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+16
-0
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+5
-3
activerecord/lib/active_record/errors.rb
activerecord/lib/active_record/errors.rb
+9
-0
activerecord/lib/active_record/nested_attributes.rb
activerecord/lib/active_record/nested_attributes.rb
+3
-1
activerecord/lib/active_record/relation/finder_methods.rb
activerecord/lib/active_record/relation/finder_methods.rb
+2
-1
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
efd2410b
*
ActiveRecord::RecordNotFound modified to store model name, primary_key and
id of the caller model. It allows the catcher of this exception to make
a better decision to what to do with it. For example consider this simple
example:
class SomeAbstractController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404
private def redirect_to_404(e)
return redirect_to(posts_url) if e.model == 'Post'
raise
end
end
*Sameer Rahmani*
*
Deprecate the keys for association
`restrict_dependent_destroy`
errors in favor
*
Deprecate the keys for association
`restrict_dependent_destroy`
errors in favor
of new key names.
of new key names.
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
efd2410b
...
@@ -162,11 +162,13 @@ def find(*ids) # :nodoc:
...
@@ -162,11 +162,13 @@ def find(*ids) # :nodoc:
}
}
record
=
statement
.
execute
([
id
],
self
,
connection
).
first
record
=
statement
.
execute
([
id
],
self
,
connection
).
first
unless
record
unless
record
raise
RecordNotFound
,
"Couldn't find
#{
name
}
with '
#{
primary_key
}
'=
#{
id
}
"
raise
RecordNotFound
.
new
(
"Couldn't find
#{
name
}
with '
#{
primary_key
}
'=
#{
id
}
"
,
name
,
primary_key
,
id
)
end
end
record
record
rescue
RangeError
rescue
RangeError
raise
RecordNotFound
,
"Couldn't find
#{
name
}
with an out of range value for '
#{
primary_key
}
'"
raise
RecordNotFound
.
new
(
"Couldn't find
#{
name
}
with an out of range value for '
#{
primary_key
}
'"
,
name
,
primary_key
)
end
end
def
find_by
(
*
args
)
# :nodoc:
def
find_by
(
*
args
)
# :nodoc:
...
@@ -199,7 +201,7 @@ def find_by(*args) # :nodoc:
...
@@ -199,7 +201,7 @@ def find_by(*args) # :nodoc:
end
end
def
find_by!
(
*
args
)
# :nodoc:
def
find_by!
(
*
args
)
# :nodoc:
find_by
(
*
args
)
or
raise
RecordNotFound
.
new
(
"Couldn't find
#{
name
}
"
)
find_by
(
*
args
)
or
raise
RecordNotFound
.
new
(
"Couldn't find
#{
name
}
"
,
name
)
end
end
def
initialize_generated_modules
# :nodoc:
def
initialize_generated_modules
# :nodoc:
...
...
activerecord/lib/active_record/errors.rb
浏览文件 @
efd2410b
...
@@ -47,6 +47,15 @@ class ConnectionNotEstablished < ActiveRecordError
...
@@ -47,6 +47,15 @@ class ConnectionNotEstablished < ActiveRecordError
# Raised when Active Record cannot find record by given id or set of ids.
# Raised when Active Record cannot find record by given id or set of ids.
class
RecordNotFound
<
ActiveRecordError
class
RecordNotFound
<
ActiveRecordError
attr_reader
:model
,
:primary_key
,
:id
def
initialize
(
message
=
nil
,
model
=
nil
,
primary_key
=
nil
,
id
=
nil
)
@primary_key
=
primary_key
@model
=
model
@id
=
id
super
(
message
)
end
end
end
# Raised by ActiveRecord::Base.save! and ActiveRecord::Base.create! methods when record cannot be
# Raised by ActiveRecord::Base.save! and ActiveRecord::Base.create! methods when record cannot be
...
...
activerecord/lib/active_record/nested_attributes.rb
浏览文件 @
efd2410b
...
@@ -561,7 +561,9 @@ def call_reject_if(association_name, attributes)
...
@@ -561,7 +561,9 @@ def call_reject_if(association_name, attributes)
end
end
def
raise_nested_attributes_record_not_found!
(
association_name
,
record_id
)
def
raise_nested_attributes_record_not_found!
(
association_name
,
record_id
)
raise
RecordNotFound
,
"Couldn't find
#{
self
.
class
.
_reflect_on_association
(
association_name
).
klass
.
name
}
with ID=
#{
record_id
}
for
#{
self
.
class
.
name
}
with ID=
#{
id
}
"
model
=
self
.
class
.
_reflect_on_association
(
association_name
).
klass
.
name
raise
RecordNotFound
.
new
(
"Couldn't find
#{
model
}
with ID=
#{
record_id
}
for
#{
self
.
class
.
name
}
with ID=
#{
id
}
"
,
model
,
'id'
,
record_id
)
end
end
end
end
end
end
activerecord/lib/active_record/relation/finder_methods.rb
浏览文件 @
efd2410b
...
@@ -85,7 +85,8 @@ def find_by(arg, *args)
...
@@ -85,7 +85,8 @@ def find_by(arg, *args)
def
find_by!
(
arg
,
*
args
)
def
find_by!
(
arg
,
*
args
)
where
(
arg
,
*
args
).
take!
where
(
arg
,
*
args
).
take!
rescue
RangeError
rescue
RangeError
raise
RecordNotFound
,
"Couldn't find
#{
@klass
.
name
}
with an out of range value"
raise
RecordNotFound
.
new
(
"Couldn't find
#{
@klass
.
name
}
with an out of range value"
,
@klass
.
name
)
end
end
# Gives a record (or N records if a parameter is supplied) without any implied
# Gives a record (or N records if a parameter is supplied) without any implied
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录