To begin with, this solution doesn't have much relation to Rails. However, you can utilize Ruby to solve the issue at hand.
To start, retrieve the canvas content as you're currently doing:
var dataURL = canvas.toDataURL("image/png");
At this stage, you have the option to simply open a new window using JavaScript and display the image directly there without requiring any server interaction:
var window = window.open();
window.document.write('<img src="'+dataURL+'"/>');
$('a.my-link').click(function(){
open().document.write('<img src="'+dataURL+'"/>');
return false;
});
For demonstration purposes, here is a quick fiddle: http://jsfiddle.net/XtUFt/
Alternatively, you could transmit the base64 string to the server and let your application create an actual image, then utilize a view to showcase it:
var base64 = dataURL.replace(/^data:image\/(png|jpg);base64,/, "") ;
var window = window.open('http://www.yourapp.com/controller/action?base64='+base64);
This example has been simplified and assumes a very small image size. For larger images, consider using a 'post' request since passing such long strings in the URL might not work efficiently!
On the server side, you can use the following code to generate the image:
require 'base64'
File.open('your/image/path/and/name.gif', 'wb') do|f|
f.write(Base64.decode64(params[:base64]))
end
Ultimately, it's just a matter of displaying the image and rendering a suitable view.