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.

...

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.

The GenericWorksController class is generated with some default behaviors. It is located at app/controllers/curation_concerns/generic_works_controller.rb

Code Block
# Generated via
#  `rails generate hyrax:work GenericWork`

module Hyrax
  class GenericWorksController < ApplicationController
    # Adds Hyrax behaviors to the controller.
    include Hyrax::WorksControllerBehavior
    include Hyrax::BreadcrumbsForWorks
    self.curation_concern_type = GenericWork
  end
end

As usual, you can add code for special processing to the controller. The controller’s main purpose is to connect it to other classes that define the model, set up forms, and display show pages.

Files defined by the controller…

Model class

The model class, which is part of the standard Rails Model-View-Controller, has its name determined by Rails convention.

model_name = controller_name minus 'Controller' (e.g. GenericWork)

Form class

The form class is used to control how metadata appears on the new/edit work form. A form class is created for each work type when the work type is generated. The controller knows about this class through the work_form_service.rb form_class method.

Default: form_class = model_name.name + Form (e.g. GenericWorkForm)

Modifying: You can change the class that is used as the form class by setting it in the controller.

Code Block
    self.form_class = GenericWorkExtForm # UNCOMMON, see note below.
Info

It is uncommon to set self.form_class as the form class is already generated (e.g. GenericWorkForm) and can hold your extensions.

Presenter class

The presenter class is used to control how metadata appears on the work show page. This class is NOT generated. See Modifying the Show Page for more information on creating a presenter class. The default presenter class is defined in works_controller_behavior.rb

Default: show_presenter = Hyrax::WorkShowPresenter

Modifying: You can change the class that is used as the presenter class by setting it in the controller.

Code Block
    self.show_presenter = GenericWorkPresenter