Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f069ec16
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,发现更多精彩内容 >>
提交
f069ec16
编写于
10月 18, 2012
作者:
F
Francesco Rodriguez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove some non-breaking spaces [ci skip]
上级
f12244b6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
13 deletion
+13
-13
actionpack/lib/action_controller/metal/strong_parameters.rb
actionpack/lib/action_controller/metal/strong_parameters.rb
+13
-13
未找到文件。
actionpack/lib/action_controller/metal/strong_parameters.rb
浏览文件 @
f069ec16
...
...
@@ -106,7 +106,7 @@ def permitted?
# end
#
# params = ActionController::Parameters.new(name: 'Francesco')
# params.permitted? #
=> false
# params.permitted? #
=> false
# Person.new(params) # => ActiveModel::ForbiddenAttributesError
# params.permit!
# params.permitted? # => true
...
...
@@ -125,7 +125,7 @@ def permit!
# the parameter at the given +key+, otherwise raises an
# <tt>ActionController::ParameterMissing</tt> error.
#
# ActionController::Parameters.new(person: { name: 'Francesco'
}).require(:person)
# ActionController::Parameters.new(person: { name: 'Francesco'
}).require(:person)
# # => {"name"=>"Francesco"}
#
# ActionController::Parameters.new(person: nil).require(:person)
...
...
@@ -141,13 +141,13 @@ def require(key)
alias
:required
:require
# Returns a new <tt>ActionController::Parameters</tt> instance that
# includes
only the given +filters+ and sets the +permitted+ for the
# object to +true+. This is useful
for limiting which attributes
# includes
only the given +filters+ and sets the +permitted+ 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' })
# permitted = params.require(:user).permit(:name, :age)
# permitted.permitted? #
=> true
# permitted.permitted? #
=> true
# permitted.has_key?(:name) # => true
# permitted.has_key?(:age) # => true
# permitted.has_key?(:role) # => false
...
...
@@ -155,7 +155,7 @@ def require(key)
# You can also use +permit+ on nested parameters, like:
#
# params = ActionController::Parameters.new({
# person:
{
# person:
{
# name: 'Francesco',
# age: 22,
# pets: [{
...
...
@@ -168,7 +168,7 @@ def require(key)
# permitted = params.permit(person: [ :name, { pets: :name } ])
# permitted.permitted? # => true
# permitted[:person][:name] # => "Francesco"
# permitted[:person][:age] #
=> nil
# permitted[:person][:age] #
=> nil
# permitted[:person][:pets][0][:name] # => "Purplish"
# permitted[:person][:pets][0][:category] # => nil
def
permit
(
*
filters
)
...
...
@@ -204,7 +204,7 @@ def permit(*filters)
# returns +nil+.
#
# params = ActionController::Parameters.new(person: { name: 'Francesco' })
# params[:person] #
=> {"name"=>"Francesco"}
# params[:person] #
=> {"name"=>"Francesco"}
# params[:none] # => nil
def
[]
(
key
)
convert_hashes_to_parameters
(
key
,
super
)
...
...
@@ -217,10 +217,10 @@ def [](key)
# is given, then that will be run and its result returned.
#
# params = ActionController::Parameters.new(person: { name: 'Francesco' })
# params.fetch(:person) # => {"name"=>"Francesco"}
# params.fetch(:none)
#
=> ActionController::ParameterMissing: param not found: none
# params.fetch(:person)
# => {"name"=>"Francesco"}
# params.fetch(:none)
#
=> ActionController::ParameterMissing: param not found: none
# params.fetch(:none, 'Francesco') # => "Francesco"
# params.fetch(:none) { 'Francesco' }
#
=> "Francesco"
# params.fetch(:none) { 'Francesco' }
#
=> "Francesco"
def
fetch
(
key
,
*
args
)
convert_hashes_to_parameters
(
key
,
super
)
rescue
KeyError
...
...
@@ -278,7 +278,7 @@ def each_element(object)
# == Strong \Parameters
#
# It provides an interface for protecting attributes from end-user
# assignment. This makes
Action Controller parameters forbidden
# assignment. This makes
Action Controller parameters forbidden
# to be used in Active Model mass assignment until they have been
# whitelisted.
#
...
...
@@ -307,7 +307,7 @@ def each_element(object)
#
# private
# # Using a private method to encapsulate the permissible parameters is
# # just
a good pattern since you'll be able to reuse the same permit
# # just
a good pattern since you'll be able to reuse the same permit
# # list between create and update. Also, you can specialize this method
# # with per-user checking of permissible attributes.
# def person_params
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录