2010-11-09 78 views
0

是否有可能不必訪問網站就可以讓rails同時執行application.html.erb頁面中所有文件的緩存?告訴Rails緩存靜態文件組

我在我的網頁下面的代碼:

<%= stylesheet_link_tag '復位', '形式', '佈局', '普通', '網頁',:緩存=> '_cached' %>

當網站首次在生產模式下加載時,這會將所有內容組合到一個_cached.css文件中。但是,我希望在網站初始化後重新生成文件。

所以步驟將

  • 啓動Rails應用程序
  • 刪除現有_cached.css文件
  • 告訴Rails重新創建application.html.erb文件中基於代碼的文件
  • 網站是活...

在待辦事項這如何任何想法?可以作爲一個耙指令或什麼?

namespace :tmp do 
    namespace :assets do 
    desc "Clears javascripts/cache and stylesheets/cache" 
    task :clear => :environment do  
     FileUtils.rm(Dir['public/javascripts/cache.js']) 
     FileUtils.rm(Dir['public/stylesheets/cache.css']) 
    end 
    end 
end 

,然後把它作爲部署腳本或斯特拉努食譜的一部分:

namespace :deploy do 
    task :start do ; end 
    task :stop do ; end 
    task :restart, :roles => :app, :except => { :no_release => true } do 
    run "cd #{current_path} && /usr/bin/env rake tmp:assets:clear RAILS_ENV=#{stage}" 
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" 
    end 
end 

回答

1

設置訪問耙子任務後

0

在一個lib /任務/文件將這個一旦網站被加載,網站文件就會生效。

namespace :assets do 

    desc "Removing existing cached files" 
    task :clear => :environment do 
    FileUtils.rm(Dir['public/javascripts/_cached.js']) 
    FileUtils.rm(Dir['public/javascripts/_ie6.js']) 
    FileUtils.rm(Dir['public/stylesheets/_cached.css']) 
    end 

    desc "Recreate the javascripts/stylesheets cache." 
    task :generate => [:environment, :clear] do 
    puts "Recreate the javascripts/stylesheets cache" 
    ActionController::Base.perform_caching = true 
    app = ActionController::Integration::Session.new(ActionController::Dispatcher.new) 
    app.get '/' 
    end 

end 
+0

沒錯。我瞭解如何清除緩存的內容,但是如何在不訪問網站的情況下再次重新生成它們? – matsko 2010-11-10 05:04:43

+0

它在第一次訪問時自動完成。只需要添加一個wget調用配方? – DGM 2010-11-10 14:10:32