Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

\uD83D\uDCD8 Instructions

Info

Highlight important information in a panel like this one. To edit this panel's color or style, select one of the options in the menu.

label = "kb-how-to-article" and type = "page" and space = "samvera"
Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@6f29e17d
sortmodified
showSpacefalse
reversetrue
typepage
labelskb-how-to-article
cql
Table of Contents
Panel
panelIconIdatlassian-info
panelIcon:info:
bgColor#B3D4FF

This tutorial assumes that you generated a work type name GenericWork. If you used a different name, substitute that name for all occurrences of GenericWork and generic_work.

Creating controlled vocabularies is not required for your app, but we will be using one in this tutorial. So we’ll go ahead and create it now.

Controlled vocabularies can be created in your app and then accessed through the Questioning Authority (QA) gem. These instructions show a simple way to create your own controlled vocabulary. To get information on accessing external authorities and details on creating local sub-autorities, see the QA README, especially the Local Sub-Authorities section.

Once the controlled vocabulary is created, you can use it for autocomplete. See Modifying the Edit Form -> Customizing the form field -> For a controlled vocabulary.

Create a vocabulary

Authorities are defined as a yml file in config/authorities. Here we will define a departments controlled vocabulary.

Code Block
## config/authorities/departments.yml
terms:
  - id: eng
    term: English
  - id: hst
    term: History
  - id: ltn
    term: Latin
  - id: zoo
    term: Zoology

Create a service to load the vocabulary

A service is required to set up Questioning Authority to return all the values, which will be used to populate the selection list, and a single value given an id, which will be used to show the value instead of the id on the show page.

Code Block
# services/departments_service.rb
module DepartmentsService
  mattr_accessor :authority
  self.authority = Qa::Authorities::Local.subauthority_for('departments')

  def self.select_all_options
    authority.all.map do |element|
      [element[:label], element[:id]]
    end
  end

  def self.label(id)
    authority.find(id).fetch('term')
  end
end