Skip to content

译稿升级到 Rails 5.1.2 #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/zh-CN/action_mailer_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ config.action_mailer.smtp_settings = {
enable_starttls_auto: true }
```

NOTE: 从 2014 年 7 月 15 日起,Google [增强了安全措施](https://support.google.com/accounts/answer/6010255),会阻止它认为不安全的应用访问。你可以在[这里](https://www.google.com/settings/security/lesssecureapps)修改 Gmail 的设置,允许访问,或者使用其他 ESP 发送电子邮件:把上面的 `'smtp.gmail.com'` 换成提供商的地址。
NOTE: 从 2014 年 7 月 15 日起,Google [增强了安全措施](https://support.google.com/accounts/answer/6010255),会阻止它认为不安全的应用访问。你可以在[这里](https://www.google.com/settings/security/lesssecureapps)修改 Gmail 的设置,允许访问。如果你的 Gmail 账户启用了双因素身份验证,则要设定一个[应用密码](https://myaccount.google.com/apppasswords),用它代替常规的密码。或者,你也可以使用其他 ESP 发送电子邮件:把上面的 `'smtp.gmail.com'` 换成提供商的地址。

<a class="anchor" id="mailer-testing"></a>

Expand Down
6 changes: 5 additions & 1 deletion source/zh-CN/active_record_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ NOTE: `find_by_*` 和 `find_by_*!` 方法是为每个属性自动生成的动态

回调在模型中注册后,将被加入队列等待执行。这个队列包含了所有模型的验证、已注册的回调和将要执行的数据库操作。

整个回调链包装在一个事务中。如果任何一个 `before` 回调方法返回 `false` 或引发异常,整个回调链就会停止执行,同时发出 `ROLLBACK` 消息来回滚事务;而 `after` 回调方法只能通过引发异常来达到相同的效果。
整个回调链包装在一个事务中。只要有回调抛出异常,回调链随即停止,并且发出 `ROLLBACK` 消息。如果想故意停止回调链,可以这么做:

```ruby
throw :abort
```

WARNING: 当回调链停止后,Rails 会重新抛出除了 `ActiveRecord::Rollback` 和 `ActiveRecord::RecordInvalid` 之外的其他异常。这可能导致那些预期 `save` 和 `update_attributes` 等方法(通常返回 `true` 或 `false` )不会引发异常的代码出错。

Expand Down
4 changes: 3 additions & 1 deletion source/zh-CN/api_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ API 应用默认包含下述中间件:
* `ActiveSupport::Cache::Strategy::LocalCache::Middleware`
* `Rack::Runtime`
* `ActionDispatch::RequestId`
* `ActionDispatch::RemoteIp`
* `Rails::Rack::Logger`
* `ActionDispatch::ShowExceptions`
* `ActionDispatch::DebugExceptions`
* `ActionDispatch::RemoteIp`
* `ActionDispatch::Reloader`
* `ActionDispatch::Callbacks`
* `ActiveRecord::Migration::CheckPending`
* `Rack::Head`
* `Rack::ConditionalGet`
* `Rack::ETag`
* `MyApi::Application::Routes`

各个中间件的作用参见 [内部中间件栈](rails_on_rack.html#internal-middleware-stack)。

Expand Down Expand Up @@ -301,6 +302,7 @@ API 应用(使用 `ActionController::API`)默认有下述控制器模块:
* `ActionController::Rescue`:提供 `rescue_from`。
* `ActionController::Instrumentation`:提供 Action Controller 定义的监测钩子(详情参见 [Action Controller](active_support_instrumentation.html#action-controller))。
* `ActionController::ParamsWrapper`:把参数散列放到一个嵌套散列中,这样在发送 POST 请求时无需指定根元素。
* `ActionController::Head`:返回只有首部没有内容的响应。

其他插件可能会添加额外的模块。`ActionController::API` 引入的模块可以在 Rails 控制台中列出:

Expand Down
2 changes: 1 addition & 1 deletion source/zh-CN/contributing_to_ruby_on_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ NOTE: 为了减轻 CI 服务器的压力,关于文档的提交消息中应该

我们欢迎人们自发把 Rails 指南翻译成其他语言。翻译时请遵照下述步骤:

* 派生项目 https://github.com/rails/rails
* 派生 https://github.com/rails/rails 项目
* 为你的语言添加一个文件夹,例如针对意大利语的 guides/source/it-IT
* 把 guides/source 中的内容复制到你创建的文件夹中,然后翻译
* 不要翻译 HTML 文件,因为那是自动生成的
Expand Down
4 changes: 2 additions & 2 deletions source/zh-CN/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -1133,11 +1133,11 @@ end
</table>
```

在上面的代码中,`link_to` 辅助方法生成“Destroy”链接的用法有点不同,其中第二个参数是具名路由(named route),还有一些选项作为其他参数。`method: :delete` 和 `data: { confirm: 'Are you sure?' }` 选项用于设置链接的 HTML5 属性,这样点击链接后 Rails 会先向用户显示一个确认对话框,然后用 `delete` 方法发起请求。这些操作是通过 JavaScript 脚本 `jquery_ujs` 实现的,这个脚本在生成应用骨架时已经被自动包含在了应用的布局中(`app/views/layouts/application.html.erb`)。如果没有这个脚本,确认对话框就无法显示。
在上面的代码中,`link_to` 辅助方法生成“Destroy”链接的用法有点不同,其中第二个参数是具名路由(named route),还有一些选项作为其他参数。`method: :delete` 和 `data: { confirm: 'Are you sure?' }` 选项用于设置链接的 HTML5 属性,这样点击链接后 Rails 会先向用户显示一个确认对话框,然后用 `delete` 方法发起请求。这些操作是通过 JavaScript 脚本 `rails-ujs` 实现的,这个脚本在生成应用骨架时已经被自动包含在了应用的布局中(`app/views/layouts/application.html.erb`)。如果没有这个脚本,确认对话框就无法显示。

![确认对话框](images/getting_started/confirm_dialog.png)

TIP: 关于 jQuery 非侵入式适配器(jQuery UJS)的更多介绍,请参阅[在 Rails 中使用 JavaScript](working_with_javascript_in_rails.html)。
TIP: 关于非侵入式 JavaScript 的更多介绍,请参阅[在 Rails 中使用 JavaScript](working_with_javascript_in_rails.html)。

恭喜你!现在你已经可以创建、显示、列出、更新和删除文章了!

Expand Down
228 changes: 0 additions & 228 deletions source/zh-CN/nested_model_forms.md

This file was deleted.

13 changes: 0 additions & 13 deletions source/zh-CN/profiling.md

This file was deleted.

14 changes: 9 additions & 5 deletions source/zh-CN/rails_on_rack.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use ActionDispatch::RemoteIp
use Sprockets::Rails::QuietAssets
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use WebConsole::Middleware
Expand All @@ -131,7 +133,7 @@ use ActionDispatch::Flash
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
run Rails.application.routes
run MyApp.application.routes
```

这里列出的默认中间件(以及其他一些)在 [内部中间件栈](#internal-middleware-stack)概述。
Expand Down Expand Up @@ -252,6 +254,12 @@ Action Controller 的大部分功能都实现成中间件。下面概述它们

在响应中设定唯一的 `X-Request-Id` 首部,并启用 `ActionDispatch::Request#request_id` 方法。

**`ActionDispatch::RemoteIp`**

检查 IP 欺骗攻击。

`Sprockets::Rails::QuietAssets`:在日志中输出对静态资源的请求。

**`Rails::Rack::Logger`**

通知日志,请求开始了。请求完毕后,清空所有相关日志。
Expand All @@ -264,10 +272,6 @@ Action Controller 的大部分功能都实现成中间件。下面概述它们

如果是本地请求,负责在日志中记录异常,并显示调试页面。

**`ActionDispatch::RemoteIp`**

检查 IP 欺骗攻击。

**`ActionDispatch::Reloader`**

提供准备和清理回调,目的是在开发环境中协助重新加载代码。
Expand Down
2 changes: 1 addition & 1 deletion source/zh-CN/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ TIP: 为了了解当前针对 Web 应用的攻击方式,最好看几个真实

TIP: CSS 注入实际上是 JavaScript 注入,因为有的浏览器(如 IE、某些版本的 Safari 和其他浏览器)允许在 CSS 中使用 JavaScript。因此,在允许 Web 应用使用自定义 CSS 时,请三思而后行。

著名的 [MySpace Samy 蠕虫](http://namb.la/popular/tech.html)是解释 CSS 注入攻击原理的最好例子。这个蠕虫只需访问用户的个人信息页面就能向 Samy(攻击者)发送好友请求。在短短几个小时内,Samy 就收到了超过一百万个好友请求,巨大的流量致使 MySpace 宕机。下面我们从技术角度来分析这个蠕虫。
著名的 [MySpace Samy 蠕虫](https://samy.pl/popular/tech.html)是解释 CSS 注入攻击原理的最好例子。这个蠕虫只需访问用户的个人信息页面就能向 Samy(攻击者)发送好友请求。在短短几个小时内,Samy 就收到了超过一百万个好友请求,巨大的流量致使 MySpace 宕机。下面我们从技术角度来分析这个蠕虫。

MySpace 禁用了很多标签,但允许使用 CSS。因此,蠕虫的作者通过下面这种方式把 JavaScript 植入 CSS 中:

Expand Down
Loading