Topic: How do I implement this image annotation javascript using AJAX?

There is a blog post http://blog.flipbit.co.uk/2009/03/jquer … lugin.html that details how to do this with PHP, but I'm not clear on how to translate this to Ruby on Rails. For the getUrl, saveUrl, and deleteUrl what do I put so that I can hook it up to my AnnotationsController and create, read, and delete Annotation models?

There is also server side code in PHP http://blog.flipbit.co.uk/2009/04/serve … image.html

jquery-image-annotate is hosted on Google code.
http://code.google.com/p/jquery-image-annotate/

Some code I have so far:

# The id is going to have to be dynamic; I'm not sure how to do that...
$(window).load(function() { 
    $(".annotatable").annotateImage({ 
        getUrl: "noIdea", 
        saveUrl: "noIdea", 
        deleteUrl: "noIdea", 
    }); 
}); 

class CreateAnnotations < ActiveRecord::Migration
  def self.up
    create_table :annotations do |t|
      t.references :image # I have a namespaced model Comment:Image that an annotation belongs to.
      t.integer :left
      t.integer :top
      t.integer :width
      t.integer :height
      t.boolean :editable
      t.text :text

      t.timestamps
    end
  end

  def self.down
    drop_table :annotations
  end
end

class AnnotationsController < ApplicationController
  def index
    @comment = Comment.find(params[:comment_id])
    @annotations = @comment.annotations.all
   
    respond_to do |format|
      format.json { render :json => @annotations }
    end
  end

  def show
    @annotation = Annotation.find(params[:id])
   
    respond_to do |format|
      format.json { render :json => @annotation }
    end
  end
end

P.S. This question is also located here: http://stackoverflow.com/questions/3924 … with-rails

Last edited by eberner (2010-10-13 13:20:18)