I'd like to draw lines on an image. Basically allow the user to draw a path for mountain trails they like.
1) Does anyone know a good simple library for drawing basic lines?
2) After a user draws a bunch of lines on an image, what would be the best way to save the data to the database?
Here's a quick solution using the canvas element and regular js (no libraries) that should help you get started.
Add a canvas element to your html page.
Add javascript to draw your image on the canvas. It will then listen for clicks, and draw the lines as the user clicks.
Realized I forgot to answer the second half of the question, regarding saving the image to a Rails DB. This is harder to answer, because it depends on what you want to do with the resulting data. If you just want the final image, I suggest you save the image to a filesystem (I use S3 to store all my images). There's a discussion on how to do this already on StackOverflow: Capture HTML Canvas as gif/jpg/png/pdf?
If you need to manipulate the path drawn, I would save the individual data points as well as a reference to the underlying image. Send the datapoints back to your Rails server via ajax, along with the url of your image. Your database table may then look something like this:
html5 canvas is the only thing I know that would allow you to do this. Here is a great article on it: http://diveintohtml5.info/canvas.html
Drawing lines
You can easily overlay the elements on top of an image so the user draws on the image.
Also, just for fun, but have you seen SVG-edit (demo)?
Saving the line data
The SketchPad script above provided drawn data in JSON that can be saved as plain text in the database. The same thing can be done on the objects from PaperJS. Here is a JSFiddle example with PaperJS (code) and here with an image as a background.