RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: darrenterhune
Site: http://headfirstproductions.ca
Here's a sudo template helper method to keep your code... DRY
def template_sudo(from, to) erb = File.read(File.expand_path("../templates/#{from}", __FILE__)) put_sudo ERB.new(erb).result(binding), to end def put_sudo(data, to) filename = File.basename(to) to_directory = File.dirname(to) put data, "/tmp/#{filename}" run "#{sudo} mv /tmp/#{filename} #{to_directory}" end
Put it in config/recipes/base.rb
config/recipes/base.rb
Here's a sudo template helper method to keep your code... DRY
Put it in
config/recipes/base.rb