RailsCasts Pro episodes are now free!

Learn more or hide this

Darren Terhune's Profile

GitHub User: darrenterhune

Site: http://headfirstproductions.ca

Comments by Darren Terhune

Avatar

Here's a sudo template helper method to keep your code... DRY

ruby
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