如何更改我的Rails應用程序以在生產模式下運行?例如,是否有配置文件(例如environment.rb)來執行此操作?將Rails應用程序更改爲生產
回答
如果mipadi's suggestion不起作用,將它添加到到config/environment.rb
# force Rails into production mode when
# you don't control web/app server and can't set it the proper way
ENV['RAILS_ENV'] ||= 'production'
謝謝!!!幫了我很多。 – 2009-12-22 21:35:30
Heroku等雲服務如何?願'ENV ['RAILS_ENV'] || ='production''也可以應用於它們嗎? – Green 2013-04-29 01:51:29
它沒有在軌道上工作4 – franzlorenzon 2014-07-17 12:45:15
您還可以將環境傳遞給腳本/服務器:
$ script/server -e production
如果你正在運行的Passenger,那麼默認是在生產中運行,在你的apache conf中:
<VirtualHost *:80>
ServerName application_name.rails.local
DocumentRoot "/Users/rails/application_name/public"
RailsEnv production ## This is the default
</VirtualHost>
如果你只是運行具有雜種或使用WEBrick本地服務器,你可以這樣做:
./script/server -e production
或在bash:
RAILS_ENV=production ./script/server
實際上覆蓋在enviornment.rb的RAILS_ENV恆也許應該是你的最後一招,因爲它可能不會留一套(見another answer我給上)
現在,這將是
rails server -e production
,或者更緊湊
rails s -e production
它適用於軌道3+項目。
或簡短的版本'軌道s -e生產' – 2012-08-21 11:06:14
像Heroku的雲服務呢?如何在它們上運行'server -e production'? – Green 2013-04-29 01:48:58
雲服務通常有指定環境的選項,但在其中,「生產」總是默認設置。 – 2013-07-01 16:52:04
在的Rails 3
添加Rails.env = ActiveSupport::StringInquirer.new('production')
到application.rb中和rails s
將工作一樣rails server -e production
module BlacklistAdmin
class Application < Rails::Application
config.encoding = "utf-8"
Rails.env = ActiveSupport::StringInquirer.new('production')
config.filter_parameters += [:password]
end
end
這是不是運行在生產環境中軌服務器的好方法「rails server -e production」,因爲然後rails作爲單線程應用程序運行,並且一次只能響應一個HTTP請求。
有關生產環境中軌的最好的文章是Production Environments - Rails 3
鏈接腐爛...可用在wayback機器雖然:[鏈接](http://web.archive.org/web/20121022083645/http: ofps.oreilly.com/titles/9780596521424/production_id35801033.html) – rosuav 2013-03-20 02:53:16
$> export RAILS_ENV=production
請確保您已在environment.rb文件中以下步驟進行。
ENV [「RAILS_ENV」] || =「生產」
如果在共享託管環境或phushion乘客你運行應用程序,你可能需要需要作出.httaccess(改變公共文件夾內)並將模式設置爲生產。
爲默認的服務器:導軌小號-e生產
爲costum服務器端口:軌道S - P m [口] -e生產,例如。軌道S - P m 3002 -e生產
rails s -e production
這將運行服務器RAILS_ENV
= 'production'
。
除了這個,你必須設置資產路徑production.rb
config.serve_static_assets = true
沒有這個你的資產將不會被加載。
對不起...當投票意向upvote。做出輕微的修改,以糾正錯誤和upvote。 – tomd 2015-09-29 23:37:40
正如其他已經公佈:rails server -e production
或者說,我個人最喜歡的:RAILS_ENV=production
rails s
RAILS_ENV=production rails s
OR
rails s -e production
缺省環境的研究與開發。
- 1. 「摧毀」不生產 - Rails應用程序
- 2. 將Coffeescript改編爲rails應用程序
- 3. 在ASP.NET應用程序的生產環境中將x86更改爲x64 dll
- 4. 何時更新生產應用程序到Rails 3.1?
- 5. 如何更改我剛部署到生產的應用程序的rails環境?
- 6. 將rails應用程序部署到生產環境
- 7. Rails應用程序認爲它在開發環境中生產
- 8. 無法爲Rails應用程序創建生產數據庫
- 9. 將此更改爲從X軸產生?
- 10. 將salesforce wsdl端點更改爲生產
- 11. 將Ruby on Rails應用程序轉換爲原生Android PhoneGap應用程序
- 12. 應用程序更改沒有生效
- 13. 更改產品的名稱爲應用程序的Xcode 4.5.2
- 14. Rails應用在生產
- 15. uWSGI適用於Rails生產應用程序?
- 16. 設置生產rails應用程序管理員用戶
- 17. 使用MongoDB,Mongomapper在生產中部署rails應用程序
- 18. 在Rails 3.2.8應用程序中從jQuery BBQ更改爲History.js
- 19. 我應該爲生產應用程序設置enableDebugLogging爲false嗎?
- 20. UTF-8麻煩Rails應用程序傳遞給生產
- 21. Rails:部署第一個應用程序 - 生產模式
- 22. Rails 3.2.1生產運行緩慢的應用程序
- 23. Rails應用程序產生額外的輸出
- 24. Ruby on Rails應用程序中的對象,生產失敗
- 25. 在生產模式下運行Rails應用程序時出錯
- 26. 開發,分段和生產環境rails應用程序
- 27. Rails應用程序沒有解析生產中的csv文件
- 28. Ruby on Rails:無法退出生產中的應用程序
- 29. 的Rails應用程序的CouchDB不生產工作
- 30. Rails應用程序未提供資產
看來第二個答案有更多的選票,你會願意給這個快速審查,並接受第二個答案,除非你有任何問題。只會幫助未來的遊客。 Thx :) – Evolve 2017-08-02 23:06:33