000f45b685d4d6ff1a171676512c382e

I would like to make this without "wget", but don't know how to get response

namespace :static do
  desc "Generate static pages for home controller"
  task :generate => :environment do
    methods =  HomeController.new.methods - ApplicationController.new.methods - ['index']
    methods.each do |action|
      system "rm #{RAILS_ROOT}/public/#{action}.html"
      system "wget http://#{SERVER_HOST}/#{action}.html -O #{RAILS_ROOT}/public/_#{action}.html -o /dev/null"
      system "mv #{RAILS_ROOT}/public/_#{action}.html #{RAILS_ROOT}/public/#{action}.html"
      p "#{action}.html"
    end
  end
end

Refactorings

No refactoring yet !

5cb7a05b6de4a6655319db9333be429c

andyjeffries

July 22, 2009, July 22, 2009 12:18, permalink

No rating. Login to rate!

I've only refactored out the wget/system calls and it's untested - but something like that should work...

require 'net/http'

namespace :static do
  desc "Generate static pages for home controller"
  task :generate => :environment do
    methods =  HomeController.new.methods - ApplicationController.new.methods - ['index']
    methods.each do |action|
      File.unlink "#{RAILS_ROOT}/public/#{action}.html"
      File.open("#{RAILS_ROOT}/public/#{action}.html", "w") do |f|
        res = Net::HTTP.start(SERVER_HOST, 80) {|http| http.get("/#{action}.html") }
        f << res.body
      end
      p "#{action}.html"
    end
  end
end

Your refactoring





Format Copy from initial code

or Cancel