Skip to content

Instantly share code, notes, and snippets.

@ascsystems
Created December 11, 2013 01:09
Show Gist options
  • Select an option

  • Save ascsystems/7903439 to your computer and use it in GitHub Desktop.

Select an option

Save ascsystems/7903439 to your computer and use it in GitHub Desktop.
class Annotation
include MongoMapper::Document
key :quote, String
key :text, String
key :ranges, Array
timestamps!
end
class AnnotationsController < ApplicationController
def index
annotations = Annotation.all
response.headers["Access-Control-Allow-Origin"]="*"
render json: annotations
end
def show
annotation = Annotation.find(params[:id])
response.headers["Access-Control-Allow-Origin"]="*"
render json: annotation
end
def new
annotation = Annotation.new
response.headers["Access-Control-Allow-Origin"]="*"
render json: annotation
end
def edit
annotation = Annotation.find(params[:id])
end
def create
response.headers["Access-Control-Allow-Origin"]="*"
render json: params
#annotation = Annotation.new(params)
#annotation = Annotation.create({quote: params[:quote], text: params[:text]})
#if annotation.save
# render json: annotation, status: :created, location: annotation
#else
# render json: annotation.errors, status: :unprocessable_entity
#end
end
def update
annotation = Annotation.find(params[:id])
response.headers["Access-Control-Allow-Origin"]="*"
if annotation.update_attributes(params)
head :no_content
else
render json: annotation.errors, status: :unprocessable_entity
end
end
def destroy
annotation = Annotation.find(params[:id])
annotation.destroy
response.headers["Access-Control-Allow-Origin"]="*"
head :no_content
end
end
Registration::Application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
resources :registrations, :annotations
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment