Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
45230813
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,发现更多精彩内容 >>
提交
45230813
编写于
6月 14, 2010
作者:
R
Rizwan Reza
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Minor changes to callbacks and conversion API docs.
上级
bf742904
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
13 deletion
+17
-13
activemodel/lib/active_model/callbacks.rb
activemodel/lib/active_model/callbacks.rb
+6
-6
activemodel/lib/active_model/conversion.rb
activemodel/lib/active_model/conversion.rb
+11
-7
未找到文件。
activemodel/lib/active_model/callbacks.rb
浏览文件 @
45230813
...
...
@@ -41,7 +41,7 @@ module ActiveModel
# # Your code here
# end
#
# You can choose not to have all three callbacks by passing a
n
hash to the
# You can choose not to have all three callbacks by passing a hash to the
# define_model_callbacks method.
#
# define_model_callbacks :create, :only => :after, :before
...
...
@@ -55,13 +55,13 @@ def self.extended(base)
end
end
# define_model_callbacks accepts
all options define_callbacks does, in case you
# want to overwrite a default. Besides that, it also accepts an :only option,
# define_model_callbacks accepts
the same options define_callbacks does, in case
#
you
want to overwrite a default. Besides that, it also accepts an :only option,
# where you can choose if you want all types (before, around or after) or just some.
#
# define_model_callbacks :initializer, :only => :after
#
# Note, the <tt>:only => <type></tt> hash will apply to all callbacks defined on
# Note, the <tt>:only => <type></tt> hash will apply to all call
backs defined on
# that method call. To get around this you can call the define_model_callbacks
# method as many times as you need.
#
...
...
@@ -73,7 +73,7 @@ def self.extended(base)
#
# You can pass in a class to before_<type>, after_<type> and around_<type>, in which
# case the call back will call that class's <action>_<type> method passing the object
# that the callback is being called on.
# that the call
back is being called on.
#
# class MyModel
# extend ActiveModel::Callbacks
...
...
@@ -84,7 +84,7 @@ def self.extended(base)
#
# class AnotherClass
# def self.before_create( obj )
# # obj is the MyModel instance that the callback is being called on
# # obj is the MyModel instance that the call
back is being called on
# end
# end
#
...
...
activemodel/lib/active_model/conversion.rb
浏览文件 @
45230813
module
ActiveModel
# Handle default conversions: to_model, to_key and to_param.
# == Active Model Conversions
#
# Handles default conversions: to_model, to_key and to_param.
#
# == Example
#
...
...
@@ -20,17 +22,19 @@ module ActiveModel
# cm.to_param #=> nil
#
module
Conversion
# If your object is already designed to implement all of the Active Model you can use
# the default to_model implementation, which simply returns self.
# If your object is already designed to implement all of the Active Model
# you can use the default to_model implementation, which simply returns
# self.
#
# If your model does not act like an Active Model object, then you should
define
#
<tt>:to_model</tt> yourself returning a proxy object that wraps your object
# with Active Model compliant methods.
# If your model does not act like an Active Model object, then you should
#
define <tt>:to_model</tt> yourself returning a proxy object that wraps
#
your object
with Active Model compliant methods.
def
to_model
self
end
# Returns an Enumerable of all (primary) key attributes or nil if persisted? is false
# Returns an Enumerable of all (primary) key attributes or nil if
# persisted? is false
def
to_key
persisted?
?
[
id
]
:
nil
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录