Class: Admin::FieldDefinitionsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/open_loam/install/templates/admin/field_definitions_controller.rb

Overview

Manages OpenLoam::FieldDefinition records: the "migration-free field" screen. Structural, not per-entity — gated on the manager role rather than a generated entity policy, since a field definition applies to a whole entity_type, not one record.

Constant Summary

Constants included from Pagination

Pagination::PER_PAGE

Instance Method Summary collapse

Methods inherited from BaseController

skip_authorization!

Methods included from Pagination

#paginate

Instance Method Details

#create ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/open_loam/install/templates/admin/field_definitions_controller.rb', line 20

def create
  @record = OpenLoam::FieldDefinition.new(permitted_params)
  @record.writable_roles = parse_roles(params.dig(:field_definition, :writable_roles))
  @record.readable_roles = parse_roles(params.dig(:field_definition, :readable_roles))

  if @record.save
    redirect_to admin_field_definitions_path(entity_type: @record.entity_type)
  else
    render :new, status: :unprocessable_entity
  end
end

#destroy ⇒ Object



32
33
34
35
36
# File 'lib/generators/open_loam/install/templates/admin/field_definitions_controller.rb', line 32

def destroy
  entity_type = @record.entity_type
  @record.destroy!
  redirect_to admin_field_definitions_path(entity_type: entity_type)
end

#index ⇒ Object



10
11
12
13
14
# File 'lib/generators/open_loam/install/templates/admin/field_definitions_controller.rb', line 10

def index
  @entity_type = params[:entity_type]
  @records = OpenLoam::FieldDefinition.order(:entity_type, :name)
  @records = @records.where(entity_type: @entity_type) if @entity_type.present?
end

#new ⇒ Object



16
17
18
# File 'lib/generators/open_loam/install/templates/admin/field_definitions_controller.rb', line 16

def new
  @record = OpenLoam::FieldDefinition.new(entity_type: params[:entity_type])
end