0

為什麼 Rails 要分 production, test, development 三種環境

 2 years ago
source link: https://blog.niclin.tw/2015/12/09/%E7%82%BA%E4%BB%80%E9%BA%BC-rails-%E8%A6%81%E5%88%86-production-test-development-%E4%B8%89%E7%A8%AE%E7%92%B0%E5%A2%83/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

development environment 開發模式,用在你的開發的時候

使用 Rails 開發可以快速的原因之一,就是當你修改一個小東西,只要重新整理瀏覽器就可以馬上看到修改後的結果。這個秘訣就在於 cache_classes = false 會讓每一次的 HTTP 請求都重新載入類別檔案。更仔細的說,當這個值是 false 的時候,Rails 會改用 Ruby 的 load 方法,每次執行都會重新載入一次。 Rails只有在連線是來自本地端的時候,才會將發生錯誤時的Call stack trace資訊給瀏覽器顯示。這個設定將所有連線都當做本地端連線,好讓開發模式時所有人連線都可以看到錯誤訊息。

production environment 正式上線模式,用在實際的上線運作環境

cache_classes = true 表示在 production 中,類別檔案載入進記憶體中就快取起來了,大大獲得效能。不像在 development 環境中每一次 HTTP 請求就會重新載入一次。 不同於 development,如果在 production 環境出現例外錯誤,不會顯示程式 call stack 訊息,而是回傳 public/500.html 頁面。

test environment 測試模式,用在自動測試時

不同於 development 或 production 碰到例外會捕捉例外後,給瀏覽器顯示出 call stack trace 或 public/500.html 畫面,在 test 模式就不處理,讓例外直接爆出。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK