You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.3 KiB

module Api
module Jurisprudence
class DoctrinesController < ::Api::BaseController
load_and_authorize_resource :jurisprudence, class: "Cdao::Jurisprudence"
load_and_authorize_resource :doctrine, class: "Doctrine", through: :jurisprudence
def index
respond_with @doctrines
end
def show
respond_with @doctrine
end
def create
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
subject_ids = attrs.delete(:subject_ids)
@doctrine = @jurisprudence.doctrines.new(attrs)
if @doctrine.save
@doctrine.subject_ids = subject_ids if subject_ids.present?
respond_with @doctrine
else
render errors: @doctrine.errors, status: 422
end
end
def update
attrs = resource_params.to_unsafe_h.deep_symbolize_keys
subject_ids = attrs.delete(:subject_ids)
if @doctrine.update(attrs)
@doctrine.subject_ids = subject_ids if subject_ids.present?
respond_with @doctrine
else
render errors: @doctrine.errors, status: 422
end
end
def destroy
@doctrine.destroy
respond_with @doctrine
end
private
def resource_params
params.permit(:content, subject_ids: [])
end
end
end
end