9 changed files with 35 additions and 101 deletions
@ -1,52 +0,0 @@ |
|||||||
class Jurisprudence::DoctrinesController < ApplicationController |
|
||||||
load_and_authorize_resource :jurisprudence, class: "Cdao::Jurisprudence" |
|
||||||
load_and_authorize_resource :doctrine, class: "Doctrine", through: :jurisprudence |
|
||||||
|
|
||||||
def create |
|
||||||
attrs = resource_params.to_unsafe_h.deep_symbolize_keys |
|
||||||
subject_ids = attrs.delete(:subject_ids) |
|
||||||
|
|
||||||
@doctrine = @jurisprudence.doctrines.new(attrs) |
|
||||||
|
|
||||||
respond_to do |format| |
|
||||||
if @doctrine.save |
|
||||||
@doctrine.subject_ids = subject_ids if subject_ids.present? |
|
||||||
|
|
||||||
format.html { redirect_to document_doctrine_path(@jurisprudence, @doctrine), notice: "Doctrine was successfully created." } |
|
||||||
else |
|
||||||
format.html { redirect_to document_doctrine_path(@jurisprudence) } |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
def update |
|
||||||
attrs = resource_params.to_unsafe_h.deep_symbolize_keys |
|
||||||
subject_ids = attrs.delete(:subject_ids) |
|
||||||
|
|
||||||
respond_to do |format| |
|
||||||
if @doctrine.update(attrs) |
|
||||||
@doctrine.subject_ids = subject_ids if subject_ids.present? |
|
||||||
|
|
||||||
format.html { redirect_to document_doctrine_path(@jurisprudence, @doctrine), notice: "Doctrine was successfully updated." } |
|
||||||
else |
|
||||||
format.html { redirect_to document_doctrine_path(@jurisprudence) } |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
def destroy |
|
||||||
respond_to do |format| |
|
||||||
if @doctrine.destroy |
|
||||||
format.html { redirect_to document_path(@jurisprudence), notice: "Doctrine was successfully destroyed." } |
|
||||||
else |
|
||||||
format.html { redirect_to document_path(@jurisprudence), alert: @doctrine.errors.full_messages } |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
private |
|
||||||
|
|
||||||
def resource_params |
|
||||||
params.permit(:content, subject_ids: []) |
|
||||||
end |
|
||||||
end |
|
||||||
@ -0,0 +1,6 @@ |
|||||||
|
class DoctrineJurisprudence < ApplicationRecord |
||||||
|
acts_as_list column: :rank, scope: %i[doctrine_id] |
||||||
|
|
||||||
|
belongs_to :doctrine, optional: false |
||||||
|
belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false |
||||||
|
end |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
class CreateDoctrineJurisprudences < ActiveRecord::Migration[6.1] |
||||||
|
def change |
||||||
|
create_table :doctrine_jurisprudences do |t| |
||||||
|
t.references :doctrine, null: false |
||||||
|
t.references :jurisprudence, null: false |
||||||
|
t.integer :rank, null: false, default: 1 |
||||||
|
|
||||||
|
t.timestamps |
||||||
|
end |
||||||
|
|
||||||
|
add_index :doctrine_jurisprudences, %i[doctrine_id jurisprudence_id], |
||||||
|
name: "index_doctrine_jurisprudences_uniqueness", |
||||||
|
unique: true |
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue