cache_page_now
Billet publié le 09/08/2007, catégorisé en Agilité, Rails
J'ai décidé de partager une petite méthode qui génère le cache d'une page..
Comment ca? ca existe déja!
Ha non attendez, c'est très différent regarder bien le nom des fonctions : caches_page (!=) caches_page_now.
Vouz avez compris? Non! Bon arrêtons de perdre notre temps, allez lire un autre billet et revenez quand vous aurez besoin d'exporter des pages web.
1 2 3 4 5 6 7 8 9 |
def caches_page_now(attrs) #be carefull to add a route for '.html' path = "#{RAILS_ROOT}/public/#{attrs[:controller]}/#{attrs[:action]}.html" #don't forget to instanciate the action variables content = render_to_string(:action => attrs[:action]) File.delete(path) if File.exists?(path) FileUtils.makedirs(File.dirname(path)) File.open(path, "wb+") { |f| f.write(content) } end |


Pourquoi ne pas réagir à cet article tant qu'il est encore chaud ?