Class: Qa::TermsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Qa::TermsController
- Defined in:
- app/controllers/qa/terms_controller.rb
Overview
This controller is used for all requests to all authorities. It will verify params and figure out which class to instantiate based on the “vocab” param. All the authotirty classes inherit from a super class so they implement the same methods.
Instance Method Summary collapse
- #check_authority ⇒ Object
- #check_search_params ⇒ Object
- #check_sub_authority ⇒ Object
- #check_vocab_param ⇒ Object
-
#index ⇒ Object
search that returns all results.
- #search ⇒ Object
- #show ⇒ Object
Instance Method Details
#check_authority ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/controllers/qa/terms_controller.rb', line 63 def begin .constantize rescue head :bad_request end end |
#check_search_params ⇒ Object
57 58 59 60 61 |
# File 'app/controllers/qa/terms_controller.rb', line 57 def check_search_params unless params[:q].present? && params[:vocab].present? head :bad_request end end |
#check_sub_authority ⇒ Object
71 72 73 74 75 |
# File 'app/controllers/qa/terms_controller.rb', line 71 def unless params[:sub_authority].nil? head :bad_request unless .constantize.(params[:sub_authority]) end end |
#check_vocab_param ⇒ Object
51 52 53 54 55 |
# File 'app/controllers/qa/terms_controller.rb', line 51 def check_vocab_param unless params[:vocab].present? head :bad_request end end |
#index ⇒ Object
search that returns all results
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/qa/terms_controller.rb', line 11 def index #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param @authority = .constantize.new @authority.search(params[:q], params[:sub_authority]) respond_to do |format| format.html { render :layout => false, json: @authority.results } format.json { render :layout => false, json: @authority.results } format.js { render :layout => false, :text => @authority.results } end end |
#search ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/qa/terms_controller.rb', line 23 def search #convert wildcard to be URI encoded params[:q].gsub!("*", "%2A") #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param @authority = .constantize.new @authority.search(params[:q], params[:sub_authority]) respond_to do |format| format.html { render :layout => false, :text => @authority.results.to_json } format.json { render :layout => false, :text => @authority.results.to_json } format.js { render :layout => false, :text => @authority.results } end end |
#show ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/qa/terms_controller.rb', line 39 def show = .constantize.new result = .get_full_record(params[:id], params[:sub_authority]) respond_to do |format| format.html { render :layout => false, :text => result.to_json } format.json { render :layout => false, :text => result.to_json } format.js { render :layout => false, :text => result } end end |