Skip to content

Instantly share code, notes, and snippets.

@yorzi
Last active December 10, 2015 17:19
Show Gist options
  • Select an option

  • Save yorzi/4467051 to your computer and use it in GitHub Desktop.

Select an option

Save yorzi/4467051 to your computer and use it in GitHub Desktop.
pushToServer: ()->
html2canvas([$(".hidden_container")[0]],{
onrendered: (canvas)=>
strDataURI = canvas.toDataURL()
@temp_container.children().remove()
@temp_container.hide()
$.ajax
url: '/svg/create'
data: {svg: "#{strDataURI}"}
dataType: 'json'
type: 'POST'
success: (response, status, xhr) =>
window.location.href = "/downloadable/" + response.id + '.png'
error: (response, status)=>
console.log response
})
# routes.rb
match "downloadable/:id(.:format)", :to => 'svg#show'
# svg_controller.rb
class SvgController < ApplicationController
require "base64"
def show
@svg = Svg.where(id: params[:id]).first
respond_to do |format|
format.png {
headers['Content-type'] = 'image/png'
headers["Content-Disposition"] = "attachment; filename=\"chart.png\""
@result = Base64.decode64(@svg.content.gsub('data:image/png;base64,', ''))
render :text => @result
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment