Skip to content

Instantly share code, notes, and snippets.

@ascsystems
Last active December 31, 2015 05:39
Show Gist options
  • Select an option

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

Select an option

Save ascsystems/7942727 to your computer and use it in GitHub Desktop.
Can access all json params but "ranges"
class AnnotationsController < ApplicationController
def index
annotations = Annotation.all
render json: annotations
end
def show
annotation = Annotation.find(params[:id])
render json: annotation
end
def new
annotation = Annotation.new
render json: annotation
end
def edit
annotation = Annotation.find(params[:id])
end
def create
annotation = Annotation.create(quote: note_params['json']['quote'], text: note_params['json']['text'], ranges: note_params['json']['ranges'])
if annotation.save
render json: annotation, status: :created
else
render json: annotation.errors, status: :unprocessable_entity
end
end
def update
annotation = Annotation.find(params[:id])
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
head :no_content
end
private
def note_params
params.permit!
end
end
{"json"=>"{\"ranges\":[{\"start\":\"/div[3]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/div[4]/div[2]/p[1]\",\"startOffset\":1130,\"end\":\"/div[3]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/div[4]/div[2]/p[1]\",\"endOffset\":1295}],\"quote\":\"se, and they played instrumental solos at breakneck speeds and used special techniques to be able to play as quickly as possible. The group’s lineup in the 1980s con\",\"text\":\"testing\"}", "action"=>"create", "controller"=>"annotations"}
{"ranges":[{"start":"/div[3]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/div[4]/div[2]/p[2]","startOffset":795,"end":"/div[3]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[4]/div[1]/div[4]/div[2]/p[2]","endOffset":884}],"quote":"htly against the strings, which creates a \"chugging,\" percussive sound. Palm muting allow","text":"test"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment