Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
70c6fb1a
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,发现更多精彩内容 >>
未验证
提交
70c6fb1a
编写于
4月 17, 2017
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Follow the style guide rules in the documetation
上级
3ee56f7b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
30 addition
and
30 deletion
+30
-30
actionpack/lib/action_controller/metal/strong_parameters.rb
actionpack/lib/action_controller/metal/strong_parameters.rb
+30
-30
未找到文件。
actionpack/lib/action_controller/metal/strong_parameters.rb
浏览文件 @
70c6fb1a
...
...
@@ -65,9 +65,9 @@ def initialize # :nodoc:
#
# params = ActionController::Parameters.new({
# person: {
# name:
'Francesco'
,
# name:
"Francesco"
,
# age: 22,
# role:
'admin'
# role:
"admin"
# }
# })
#
...
...
@@ -115,7 +115,7 @@ def initialize # :nodoc:
# You can fetch values of <tt>ActionController::Parameters</tt> using either
# <tt>:key</tt> or <tt>"key"</tt>.
#
# params = ActionController::Parameters.new(key:
'value'
)
# params = ActionController::Parameters.new(key:
"value"
)
# params[:key] # => "value"
# params["key"] # => "value"
class
Parameters
...
...
@@ -215,13 +215,13 @@ class Parameters
# class Person < ActiveRecord::Base
# end
#
# params = ActionController::Parameters.new(name:
'Francesco'
)
# params = ActionController::Parameters.new(name:
"Francesco"
)
# params.permitted? # => false
# Person.new(params) # => ActiveModel::ForbiddenAttributesError
#
# ActionController::Parameters.permit_all_parameters = true
#
# params = ActionController::Parameters.new(name:
'Francesco'
)
# params = ActionController::Parameters.new(name:
"Francesco"
)
# params.permitted? # => true
# Person.new(params) # => #<Person id: nil, name: "Francesco">
def
initialize
(
parameters
=
{})
...
...
@@ -243,8 +243,8 @@ def ==(other)
# representation of the parameters with all unpermitted keys removed.
#
# params = ActionController::Parameters.new({
# name:
'Senjougahara Hitagi'
,
# oddity:
'Heavy stone crab'
# name:
"Senjougahara Hitagi"
,
# oddity:
"Heavy stone crab"
# })
# params.to_h
# # => ActionController::UnfilteredParameters: unable to convert unfiltered parameters to hash
...
...
@@ -263,8 +263,8 @@ def to_h
# with all unpermitted keys removed.
#
# params = ActionController::Parameters.new({
# name:
'Senjougahara Hitagi'
,
# oddity:
'Heavy stone crab'
# name:
"Senjougahara Hitagi"
,
# oddity:
"Heavy stone crab"
# })
# params.to_hash
# # => ActionController::UnfilteredParameters: unable to convert unfiltered parameters to hash
...
...
@@ -279,8 +279,8 @@ def to_hash
# query string:
#
# params = ActionController::Parameters.new({
# name:
'David'
,
# nationality:
'Danish'
# name:
"David"
,
# nationality:
"Danish"
# })
# params.to_query
# # => "name=David&nationality=Danish"
...
...
@@ -288,10 +288,10 @@ def to_hash
# An optional namespace can be passed to enclose key names:
#
# params = ActionController::Parameters.new({
# name:
'David'
,
# nationality:
'Danish'
# name:
"David"
,
# nationality:
"Danish"
# })
# params.to_query(
'user'
)
# params.to_query(
"user"
)
# # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
#
# The string pairs "key=value" that conform the query string
...
...
@@ -308,8 +308,8 @@ def to_query(*args)
# parameters.
#
# params = ActionController::Parameters.new({
# name:
'Senjougahara Hitagi'
,
# oddity:
'Heavy stone crab'
# name:
"Senjougahara Hitagi"
,
# oddity:
"Heavy stone crab"
# })
# params.to_unsafe_h
# # => {"name"=>"Senjougahara Hitagi", "oddity" => "Heavy stone crab"}
...
...
@@ -354,7 +354,7 @@ def permitted?
# class Person < ActiveRecord::Base
# end
#
# params = ActionController::Parameters.new(name:
'Francesco'
)
# params = ActionController::Parameters.new(name:
"Francesco"
)
# params.permitted? # => false
# Person.new(params) # => ActiveModel::ForbiddenAttributesError
# params.permit!
...
...
@@ -376,7 +376,7 @@ def permit!
# When passed a single key, if it exists and its associated value is
# either present or the singleton +false+, returns said value:
#
# ActionController::Parameters.new(person: { name:
'Francesco'
}).require(:person)
# ActionController::Parameters.new(person: { name:
"Francesco"
}).require(:person)
# # => <ActionController::Parameters {"name"=>"Francesco"} permitted: false>
#
# Otherwise raises <tt>ActionController::ParameterMissing</tt>:
...
...
@@ -409,7 +409,7 @@ def permit!
# Technically this method can be used to fetch terminal values:
#
# # CAREFUL
# params = ActionController::Parameters.new(person: { name:
'Finn'
})
# params = ActionController::Parameters.new(person: { name:
"Finn"
})
# name = params.require(:person).require(:name) # CAREFUL
#
# but take into account that at some point those ones have to be permitted:
...
...
@@ -439,7 +439,7 @@ def require(key)
# for the object to +true+. This is useful for limiting which attributes
# should be allowed for mass updating.
#
# params = ActionController::Parameters.new(user: { name:
'Francesco', age: 22, role: 'admin'
})
# params = ActionController::Parameters.new(user: { name:
"Francesco", age: 22, role: "admin"
})
# permitted = params.require(:user).permit(:name, :age)
# permitted.permitted? # => true
# permitted.has_key?(:name) # => true
...
...
@@ -459,7 +459,7 @@ def require(key)
# You may declare that the parameter should be an array of permitted scalars
# by mapping it to an empty array:
#
# params = ActionController::Parameters.new(tags: [
'rails', 'parameters'
])
# params = ActionController::Parameters.new(tags: [
"rails", "parameters"
])
# params.permit(tags: [])
#
# Sometimes it is not possible or convenient to declare the valid keys of
...
...
@@ -475,11 +475,11 @@ def require(key)
#
# params = ActionController::Parameters.new({
# person: {
# name:
'Francesco'
,
# name:
"Francesco"
,
# age: 22,
# pets: [{
# name:
'Purplish'
,
# category:
'dogs'
# name:
"Purplish"
,
# category:
"dogs"
# }]
# }
# })
...
...
@@ -498,8 +498,8 @@ def require(key)
# params = ActionController::Parameters.new({
# person: {
# contact: {
# email:
'none@test.com'
,
# phone:
'555-1234'
# email:
"none@test.com"
,
# phone:
"555-1234"
# }
# }
# })
...
...
@@ -532,7 +532,7 @@ def permit(*filters)
# Returns a parameter for the given +key+. If not found,
# returns +nil+.
#
# params = ActionController::Parameters.new(person: { name:
'Francesco'
})
# params = ActionController::Parameters.new(person: { name:
"Francesco"
})
# params[:person] # => <ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# params[:none] # => nil
def
[]
(
key
)
...
...
@@ -551,11 +551,11 @@ def []=(key, value)
# if more arguments are given, then that will be returned; if a block
# is given, then that will be run and its result returned.
#
# params = ActionController::Parameters.new(person: { name:
'Francesco'
})
# params = ActionController::Parameters.new(person: { name:
"Francesco"
})
# params.fetch(:person) # => <ActionController::Parameters {"name"=>"Francesco"} permitted: false>
# params.fetch(:none) # => ActionController::ParameterMissing: param is missing or the value is empty: none
# params.fetch(:none,
'Francesco'
) # => "Francesco"
# params.fetch(:none) {
'Francesco'
} # => "Francesco"
# params.fetch(:none,
"Francesco"
) # => "Francesco"
# params.fetch(:none) {
"Francesco"
} # => "Francesco"
def
fetch
(
key
,
*
args
)
convert_value_to_parameters
(
@parameters
.
fetch
(
key
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录