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.
 
 
 
 
 

87 lines
2.2 KiB

class SubjectIndexesController < ApplicationController
include JurisprudenceSearch
load_and_authorize_resource :subject_index, class: "Cdao::Subject", except: %i[search]
def index; end
def new; end
def edit; end
def show; end
def search
@search = search_subject(search_params)
@subjects = @search.results
respond_to do |format|
format.html
end
end
def create
respond_to do |format|
if @subject_index.save
format.html { redirect_to subject_index_path(@subject_index), notice: "Subject Index was successfully created." }
else
format.html { render :new }
end
end
end
def update
respond_to do |format|
if @subject_index.update(resource_params)
format.html { redirect_to subject_index_path(@subject_index), notice: "Subject Index was successfully updated." }
else
format.html { render :edit }
end
end
end
def destroy
respond_to do |format|
if @subject_index.destroy
format.html { redirect_to subject_indexes_path, notice: "Subject Index was successfully destroyed." }
else
format.html { redirect_to subject_index_path(@subject_index), alert: @subject_index.errors.full_messages }
end
end
end
private
def search_subject(args)
Cdao::Subject.search do
if args[:q].present?
fulltext args[:q], fields: %i[name], query_phrase_slop: 0, minimum_match: 1 do
%i[name code series_no].each { |field| highlight field, max_snippets: 3, fragment_size: 100 }
end
end
if args[:name].present?
fulltext args[:q], fields: %i[name], query_phrase_slop: 0, minimum_match: 1 do
highlight :name, max_snippets: 3, fragment_size: 100
end
end
if args[:parent_id].present?
with :parent_id, args[:parent_id].to_i
else
with :parent_id, nil
end
order_by :name, :asc
paginate page: args[:page] || 1, per_page: args[:per_page] || 20
end
end
def resource_params
params.permit(:name, parent_id)
end
def search_params
params.permit(:name, :parent_id, :state, doctrine_ids: [])
end
end