2 changed files with 57 additions and 0 deletions
@ -0,0 +1,56 @@
|
||||
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 |
||||
Loading…
Reference in new issue