Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9f7442a3
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,发现更多精彩内容 >>
提交
9f7442a3
编写于
7月 04, 2011
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use an instance variable to store the current masss assignment options
上级
78ff00d1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
13 deletion
+18
-13
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+14
-9
activerecord/lib/active_record/nested_attributes.rb
activerecord/lib/active_record/nested_attributes.rb
+4
-4
未找到文件。
activerecord/lib/active_record/base.rb
浏览文件 @
9f7442a3
...
...
@@ -1709,27 +1709,24 @@ def assign_attributes(new_attributes, options = {})
return
unless
new_attributes
attributes
=
new_attributes
.
stringify_keys
role
=
options
[
:as
]
||
:default
multi_parameter_attributes
=
[]
@mass_assignment_options
=
options
unless
options
[
:without_protection
]
attributes
=
sanitize_for_mass_assignment
(
attributes
,
role
)
attributes
=
sanitize_for_mass_assignment
(
attributes
,
mass_assignment_
role
)
end
attributes
.
each
do
|
k
,
v
|
if
k
.
include?
(
"("
)
multi_parameter_attributes
<<
[
k
,
v
]
elsif
respond_to?
(
"
#{
k
}
="
)
send
(
"
#{
k
}
="
,
v
)
else
method_name
=
"
#{
k
}
="
if
respond_to?
(
method_name
)
method
(
method_name
).
arity
==
-
2
?
send
(
method_name
,
v
,
options
)
:
send
(
method_name
,
v
)
else
raise
(
UnknownAttributeError
,
"unknown attribute:
#{
k
}
"
)
end
raise
(
UnknownAttributeError
,
"unknown attribute:
#{
k
}
"
)
end
end
@mass_assignment_options
=
nil
assign_multiparameter_attributes
(
multi_parameter_attributes
)
end
...
...
@@ -1894,6 +1891,14 @@ def clone_attribute_value(reader_method, attribute_name)
value
end
def
mass_assignment_options
@mass_assignment_options
||=
{}
end
def
mass_assignment_role
mass_assignment_options
[
:as
]
||
:default
end
private
# Under Ruby 1.9, Array#flatten will call #to_ary (recursively) on each of the elements
...
...
activerecord/lib/active_record/nested_attributes.rb
浏览文件 @
9f7442a3
...
...
@@ -276,15 +276,15 @@ def accepts_nested_attributes_for(*attr_names)
type
=
(
reflection
.
collection?
?
:collection
:
:one_to_one
)
# def pirate_attributes=(attributes
, assignment_opts = {}
)
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes,
assignment_opt
s)
# def pirate_attributes=(attributes)
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes,
mass_assignment_option
s)
# end
class_eval
<<-
eoruby
,
__FILE__
,
__LINE__
+
1
if method_defined?(:
#{
association_name
}
_attributes=)
remove_method(:
#{
association_name
}
_attributes=)
end
def
#{
association_name
}
_attributes=(attributes
, assignment_opts = {}
)
assign_nested_attributes_for_
#{
type
}
_association(:
#{
association_name
}
, attributes,
assignment_opt
s)
def
#{
association_name
}
_attributes=(attributes)
assign_nested_attributes_for_
#{
type
}
_association(:
#{
association_name
}
, attributes,
mass_assignment_option
s)
end
eoruby
else
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录