Skip to content

Commit ec56d61

Browse files
committed
Site updated @ Sat Oct 25 21:34:28 CST 2014
1 parent 7d8ba10 commit ec56d61

File tree

5 files changed

+23
-133
lines changed

5 files changed

+23
-133
lines changed

4_0_release_notes.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ <h4 id="action-pack-deprecations">10.2 Deprecations</h4><h3 id="active-record">1
423423
The method <code>change_table</code> is also reversible, as long as its block doesn't call <code>remove</code>, <code>change</code> or <code>change_default</code>
424424
</li>
425425
<li>New method <code>reversible</code> makes it possible to specify code to be run when migrating up or down.
426-
See the <a href="https://github.com/rails/rails/blob/master/guides/source/migrations.md#using-the-reversible-method">Guide on Migration</a>
426+
See the <a href="https://github.com/rails/rails/blob/master/guides/source/active_record_migrations.md#using-reversible">Guide on Migration</a>
427427
</li>
428428
<li>New method <code>revert</code> will revert a whole migration or the given block.
429429
If migrating down, the given migration / block is run normally.
430-
See the <a href="https://github.com/rails/rails/blob/master/guides/source/migrations.md#reverting-previous-migrations">Guide on Migration</a>
430+
See the <a href="https://github.com/rails/rails/blob/master/guides/source/active_record_migrations.md#reverting-previous-migrations">Guide on Migration</a>
431431
</li>
432432
</ul>
433433
</li>

action_controller_overview.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,16 +1218,16 @@ <h3 id="過濾-log">13 過濾 Log</h3><p>Rails 為每個環境都存有 Log 檔
12181218
</ul>
12191219
<div class="code_container">
12201220
<pre class="brush: plain; gutter: false; toolbar: false">
1221-
errors/
1222-
not_found.html.erb
1223-
unprocessable_entity.html.erb
1224-
server_error.html.erb
1225-
layouts/
1226-
error.html.erb
1221+
errors/
1222+
not_found.html.erb
1223+
unprocessable_entity.html.erb
1224+
server_error.html.erb
1225+
layouts/
1226+
error.html.erb
12271227

12281228
</pre>
12291229
</div>
1230-
<p>別忘記在 Controller 設定正確的錯誤碼(如上所示)。錯誤頁面要避免使用資料庫,或進行任何複雜的操作。因為使用者已經到了錯誤頁面這裡,在錯誤頁面產生另外的錯誤會造成不必要的問題。</p><h3 id="強制使用-https-協定">15 強制使用 HTTPS 協定</h3><p>有時候出於安全性考量,可能想讓特定的 Controller 只可以透過 HTTPS 來存取。可以在 Controller 使用 <code>force_ssl</code> 方法:</p><div class="code_container">
1230+
<p>別忘記在 Controller 設定正確的錯誤碼(如上所示)。</p><div class="warning"><p>錯誤頁面要避免對資料庫進行操作,或是進行任何複雜的操作。因為使用者已經到了錯誤頁面這裡,在錯誤頁面產生另外的錯誤會造成不必要的問題。</p></div><h3 id="強制使用-https-協定">15 強制使用 HTTPS 協定</h3><p>有時候出於安全性考量,可能想讓特定的 Controller 只可以透過 HTTPS 來存取。可以在 Controller 使用 <code>force_ssl</code> 方法:</p><div class="code_container">
12311231
<pre class="brush: ruby; gutter: false; toolbar: false">
12321232
class DinnerController
12331233
force_ssl

active_job_basics.html

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -261,129 +261,11 @@ <h4 id="任務排程">3.2 任務排程</h4><p>將任務加入排程:</p><div c
261261

262262
</pre>
263263
</div>
264-
<p>就這麼簡單!</p><h3 id="執行任務">4 執行任務</h3><p>若無設定連接器,任務會即刻執行。</p><h4 id="後台">4.1 後台</h4><p>Active Job 針對提供以下佇列後台的連接器:</p>
265-
<ul>
266-
<li><a href="https://github.com/nesquena/backburner">Backburner</a></li>
267-
<li><a href="https://github.com/collectiveidea/delayed_job">Delayed Job</a></li>
268-
<li><a href="https://github.com/bkeepers/qu">Qu</a></li>
269-
<li><a href="https://github.com/chanks/que">Que</a></li>
270-
<li><a href="https://github.com/ryandotsmith/queue_classic/tree/v2.2.3">QueueClassic 2.x</a></li>
271-
<li><a href="https://github.com/resque/resque/tree/1-x-stable">Resque 1.x</a></li>
272-
<li><a href="https://github.com/mperham/sidekiq">Sidekiq</a></li>
273-
<li><a href="https://github.com/jondot/sneakers">Sneakers</a></li>
274-
<li><a href="https://github.com/brandonhilkert/sucker_punch">Sucker Punch</a></li>
275-
</ul>
276-
<h5 id="各後台功能特色">4.1.1 各後台功能特色</h5>
277-
<table>
278-
<thead>
279-
<tr>
280-
<th></th>
281-
<th>Async</th>
282-
<th>Queues</th>
283-
<th>Delayed</th>
284-
<th>Priorities</th>
285-
<th>Timeout</th>
286-
<th>Retries</th>
287-
</tr>
288-
</thead>
289-
<tbody>
290-
<tr>
291-
<td><strong>Backburner</strong></td>
292-
<td>Yes</td>
293-
<td>Yes</td>
294-
<td>Yes</td>
295-
<td>Yes</td>
296-
<td>Job</td>
297-
<td>Global</td>
298-
</tr>
299-
<tr>
300-
<td><strong>Delayed Job</strong></td>
301-
<td>Yes</td>
302-
<td>Yes</td>
303-
<td>Yes</td>
304-
<td>Job</td>
305-
<td>Global</td>
306-
<td>Global</td>
307-
</tr>
308-
<tr>
309-
<td><strong>Que</strong></td>
310-
<td>Yes</td>
311-
<td>Yes</td>
312-
<td>Yes</td>
313-
<td>Job</td>
314-
<td>No</td>
315-
<td>Job</td>
316-
</tr>
317-
<tr>
318-
<td><strong>Queue Classic</strong></td>
319-
<td>Yes</td>
320-
<td>Yes</td>
321-
<td>No*</td>
322-
<td>No</td>
323-
<td>No</td>
324-
<td>No</td>
325-
</tr>
326-
<tr>
327-
<td><strong>Resque</strong></td>
328-
<td>Yes</td>
329-
<td>Yes</td>
330-
<td>Yes (Gem)</td>
331-
<td>Queue</td>
332-
<td>Global</td>
333-
<td>Yes</td>
334-
</tr>
335-
<tr>
336-
<td><strong>Sidekiq</strong></td>
337-
<td>Yes</td>
338-
<td>Yes</td>
339-
<td>Yes</td>
340-
<td>Queue</td>
341-
<td>No</td>
342-
<td>Job</td>
343-
</tr>
344-
<tr>
345-
<td><strong>Sneakers</strong></td>
346-
<td>Yes</td>
347-
<td>Yes</td>
348-
<td>No</td>
349-
<td>Queue</td>
350-
<td>Queue</td>
351-
<td>No</td>
352-
</tr>
353-
<tr>
354-
<td><strong>Sucker Punch</strong></td>
355-
<td>Yes</td>
356-
<td>Yes</td>
357-
<td>No</td>
358-
<td>No</td>
359-
<td>No</td>
360-
<td>No</td>
361-
</tr>
362-
<tr>
363-
<td><strong>Active Job Inline</strong></td>
364-
<td>No</td>
365-
<td>Yes</td>
366-
<td>N/A</td>
367-
<td>N/A</td>
368-
<td>N/A</td>
369-
<td>N/A</td>
370-
</tr>
371-
<tr>
372-
<td><strong>Active Job</strong></td>
373-
<td>Yes</td>
374-
<td>Yes</td>
375-
<td>Yes</td>
376-
<td>No</td>
377-
<td>No</td>
378-
<td>No</td>
379-
</tr>
380-
</tbody>
381-
</table>
382-
<div class="note"><p>* Queue Classic 不支援任務排程。但可以自己用 queue_classic-later Gem 來實作,詳細請參考 <code>ActiveJob::QueueAdapters::QueueClassicAdapter</code> 的文件。</p></div><h4 id="切換後台">4.2 切換後台</h4><p>切換後台的連接器非常簡單:</p><div class="code_container">
264+
<p>就這麼簡單!</p><h3 id="執行任務">4 執行任務</h3><p>若無設定連接器,任務會即刻執行。</p><h4 id="後台">4.1 後台</h4><p>Active Job 內建支援多種佇列後台的連接器(Sidekiq、Resque、Delayed Job 等)。完整連接器列表請見 <a href="http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html">ActiveJob::QueueAdapters</a> 的 API 文件。</p><h4 id="切換後台">4.2 切換後台</h4><p>切換後台的連接器非常簡單:</p><div class="code_container">
383265
<pre class="brush: ruby; gutter: false; toolbar: false">
384266
# be sure to have the adapter gem in your Gemfile and follow the adapter specific
385267
# installation and deployment instructions
386-
YourApp::Application.config.active_job.queue_adapter = :sidekiq
268+
Rails.Application.config.active_job.queue_adapter = :sidekiq
387269

388270
</pre>
389271
</div>

active_record_basics.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ <h4 id="資料庫綱要慣例">2.2 資料庫綱要慣例</h4><p>Active Record
281281
<code>lock_version</code> - 加入 <a href="http://api.rubyonrails.org/classes/ActiveRecord/Locking.html">optimistic
282282
locking</a> 功能至 Model。</li>
283283
<li>
284-
<code>type</code> - 表示 Model 開啟了<a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#label-Single+table+inheritance">單表繼承</a>功能。</li>
284+
<code>type</code> - 表示 Model 開啟了<a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord::Base-label-Single+table+inheritance">單表繼承</a>功能。</li>
285285
<li>
286286
<code>(association_name)_type</code> - 儲存
287287
<a href="association_basics.html#polymorphic-associations">多態關聯</a> 所需的類型資料。</li>

active_record_validations.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ <h4 id="validates-associated">2.2 <code>validates_associated</code>
452452

453453
</pre>
454454
</div>
455-
<p><code>format</code> 預設錯誤訊息是 <em>"is invalid"</em></p><h4 id="inclusion">2.6 <code>inclusion</code>
455+
<p>也可以使用 <code>:without</code> 來指定沒有匹配的屬性。</p><p><code>format</code> 預設錯誤訊息是 <em>"is invalid"</em></p><h4 id="inclusion">2.6 <code>inclusion</code>
456456
</h4><p>這個方法驗證屬性是否“屬於”某個給定的集合。集合可以是任何 <code>Enumerable</code> 的物件。</p><div class="code_container">
457457
<pre class="brush: ruby; gutter: false; toolbar: false">
458458
class Coffee &lt; ActiveRecord::Base
@@ -568,7 +568,15 @@ <h4 id="validates-associated">2.2 <code>validates_associated</code>
568568

569569
</pre>
570570
</div>
571-
<p>如透過 <code>has_one</code><code>has_many</code> 關係來驗證關聯的物件是否存在,則會對該物件呼叫 <code>blank?</code><code>marked_for_destruction?</code>,來確定存在性。</p><p>由於 <code>false.blank?</code><code>true</code>,如果想驗證布林欄位的存在性,應該要使用 <code>validates :field_name, inclusion: { in: [true, false] }</code></p><p>預設錯誤訊息是 <em>"can't be blank"</em></p><h4 id="absence">2.10 <code>absence</code>
571+
<p>如透過 <code>has_one</code><code>has_many</code> 關係來驗證關聯的物件是否存在,則會對該物件呼叫 <code>blank?</code><code>marked_for_destruction?</code>,來確定存在性。</p><p>由於 <code>false.blank?</code><code>true</code>,如果想驗證布林欄位的存在性,應該要使用下列的驗證方法:</p><div class="code_container">
572+
<pre class="brush: ruby; gutter: false; toolbar: false">
573+
validates :boolean_field_name, presence: true
574+
validates :boolean_field_name, inclusion: { in: [true, false] }
575+
validates :boolean_field_name, exclusion: { in: [nil] }
576+
577+
</pre>
578+
</div>
579+
<p>預設錯誤訊息是 <em>"can't be blank"</em></p><h4 id="absence">2.10 <code>absence</code>
572580
</h4><p>這個方法驗證是否“不存在”。使用 <code>present?</code> 來檢查數值是否為非 <code>nil</code> 或非空字串(僅有空白的字串也是空字串)。</p><div class="code_container">
573581
<pre class="brush: ruby; gutter: false; toolbar: false">
574582
class Person &lt; ActiveRecord::Base
@@ -682,7 +690,7 @@ <h4 id="validates-associated">2.2 <code>validates_associated</code>
682690
<pre class="brush: ruby; gutter: false; toolbar: false">
683691
class Person &lt; ActiveRecord::Base
684692
validates_each :name, :surname do |record, attr, value|
685-
record.errors.add(attr, 'must start with upper case') if value =~ /\A[a-z]/
693+
record.errors.add(attr, 'must start with upper case') if value =~ /\A[[:lower:]]/
686694
end
687695
end
688696

0 commit comments

Comments
 (0)