class Doctrine::AnnotationsController < ApplicationController load_and_authorize_resource :doctrine, class: "Doctrine" load_and_authorize_resource :annotation, class: "Annotation", through: :doctrine def create attrs = resource_params.to_unsafe_h document_id = attrs.delete(:document_id) @annotation = @doctrine.annotations.new(attrs) if document_id.present? @annotation.document = Cdao::Jurisprudence.find(attrs.delete(:document_id)) end respond_to do |format| if @annotation.save format.html { redirect_to document_path(@doctrine.document) , notice: "Doctrine Annotation was successfully created." } else format.html { redirect_to document_path(@doctrine.document) } end end end def update attrs = resource_params.to_unsafe_h document_id = attrs.delete(:document_id) attrs[:document] = Cdao::Jurisprudence.find(document_id) if document_id.present? respond_to do |format| if @annotation.update(attrs) format.html { redirect_to document_path(@doctrine.document), notice: "Doctrine Annotation was successfully updated." } else format.html { redirect_to document_path(@doctrine.document) } end end end def destroy respond_to do |format| if @annotation.destroy format.html { redirect_to subject_indexes_path, notice: "Doctrine Annotation was successfully destroyed." } else format.html { redirect_to document_path(@doctrine.document), alert: @annotation.errors.full_messages } end end end private def resource_params params.permit(:document_id, :phil_rep, :editor_notes, :rank, annomark_ids: []) end end