Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9e98d2da
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,发现更多精彩内容 >>
提交
9e98d2da
编写于
3月 18, 2012
作者:
M
Mark Thomson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revised comments for respond_with
上级
a188a1d2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
18 addition
and
17 deletion
+18
-17
actionpack/lib/action_controller/metal/mime_responds.rb
actionpack/lib/action_controller/metal/mime_responds.rb
+18
-17
未找到文件。
actionpack/lib/action_controller/metal/mime_responds.rb
浏览文件 @
9e98d2da
...
...
@@ -209,27 +209,28 @@ def respond_to(*mimes, &block)
# end
# end
#
# then the mime-type of the response
will be
selected based on the
# then the mime-type of the response
is typically
selected based on the
# request's Accept header and the set of available formats declared
# by previous calls to the controller's class method +respond_to+.
# by previous calls to the controller's class method +respond_to+. Alternatively
# the mime-type can be selected by explicitly setting <tt>request.format</tt> in
# the controller.
#
# If an acceptable response is not in the list of formats declared by
# +respond_to+, the application will return a '406 - not acceptable'
# status code. Otherwise, the default response will render
# If an acceptable response is not found, the application returns a
# '406 - not acceptable' status. Otherwise, the default response is to render
# a template named after the current action and the selected format,
# e.g. <tt>index.html.erb</tt>. If no template is available, the behavior
# depends on the selected format:
#
# * for an html response - if the request method
wa
s +get+, an exception
#
will be
raised but for other requests such as +post+ the response
# * for an html response - if the request method
i
s +get+, an exception
#
is
raised but for other requests such as +post+ the response
# depends on whether the resource has any validation errors (i.e.
# assuming that an attempt has been made to save the resource,
# e.g. by a +create+ action) -
# 1. If there are no errors, i.e. the resource
,
# was saved successfully, the response
will +redirect+
to the resource
# 1. If there are no errors, i.e. the resource
# was saved successfully, the response
+redirect+'s
to the resource
# i.e. its +show+ action.
# 2. If there are validation errors, the response
#
will instead render
a default action, which is <tt>:new</tt> for a
#
renders
a default action, which is <tt>:new</tt> for a
# +post+ request or <tt>:edit</tt> for +put+.
# Thus an example like this -
#
...
...
@@ -260,22 +261,22 @@ def respond_to(*mimes, &block)
# * for a javascript request - if the template isn't found, an exception is
# raised.
# * for other requests - i.e. data formats such as xml, json, csv etc, if
# the resource passed to +respond
s
_with+ responds to <code>to_<format></code>,
# the method
will attempt
to render the resource in the requested format
# the resource passed to +respond_with+ responds to <code>to_<format></code>,
# the method
attempts
to render the resource in the requested format
# directly, e.g. for an xml request, the response is equivalent to calling
# <code>render :xml => resource</code>.
#
# === Nested resources
#
# As outlined above, the +resources+ argument passed to +respond_with+
# can p
otentially p
lay two roles. It can be used to generate the redirect url
# can play two roles. It can be used to generate the redirect url
# for successful html requests (e.g. for +create+ actions when
# no template exists), while for formats other than html and javascript
# it is the object that gets rendered, by being converted directly to the
# required format (again assuming no template exists).
#
# For
the redirection of
successful html requests, +respond_with+ also supports
# the use of nested resources, which are supplied in the same way as
you do
# For
redirecting
successful html requests, +respond_with+ also supports
# the use of nested resources, which are supplied in the same way as
# in <code>form_for</code> and <code>polymorphic_url</code>. For example -
#
# def create
...
...
@@ -288,7 +289,7 @@ def respond_to(*mimes, &block)
# This would cause +respond_with+ to redirect to <code>project_task_url</code>
# instead of <code>task_url</code>. For request formats other than html or
# javascript, if multiple resources are passed in this way, it is the last
# one specified that
will be
rendered.
# one specified that
is
rendered.
#
# === Customizing response behavior
#
...
...
@@ -310,7 +311,7 @@ def respond_to(*mimes, &block)
# do not have to first be declared using the class method +respond_to+.
#
# Also, a hash passed to +respond_with+ immediately after the specified
# resource(s)
will be
interpreted as a set of options relevant to all
# resource(s)
is
interpreted as a set of options relevant to all
# formats. Any option accepted by +render+ can be used, e.g.
# respond_with @people, :status => 200
# However, note that these options are ignored after an unsuccessful attempt
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录