Module: Mongoid::DocumentEditor::DocumentsHelper

Included in:
ApplicationController
Defined in:
app/helpers/mongoid/document_editor/documents_helper.rb

Instance Method Summary collapse

Instance Method Details

#cell_value(document, header, config) ⇒ Object



34
35
36
37
38
39
40
# File 'app/helpers/mongoid/document_editor/documents_helper.rb', line 34

def cell_value(document, header, config)
  if config[:value] && config[:value].respond_to?(:call)
    config[:value].call(document)
  else
    document.send(header)
  end
end

#document_edit_field(form, klass, document, name, config) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/mongoid/document_editor/documents_helper.rb', line 5

def document_edit_field(form, klass, document, name, config)
  name = name.to_s
  return nil if private_field?(name)

  values = config.fetch(:values, nil)
  if values.respond_to?(:call) && values.arity == 1
    values = values.call(document)
  elsif values.respond_to?(:call)
    values = values.call
  end

  label   = config.fetch(:label, :name)
  value   = config.fetch(:value, :id)
  type    = config.fetch(:type, nil)
  options = {}
  options = {as: :boolean} if klass.fields[name].type == Boolean
  options = {as: :numeric} if klass.fields[name].type == Integer
  options = {as: :text}    if type == :text
  options = {collection: values} if values.present?

  options.merge!(label_method: label, value_method: value) if config[:label] && config[:value]

  if klass.fields[name].type == Array && values
    return form.collection_check_boxes(name, values, value, label)
  else
    return form.input(name, options)
  end
end

#model_param(model) ⇒ Object



42
43
44
# File 'app/helpers/mongoid/document_editor/documents_helper.rb', line 42

def model_param(model)
  model.to_s.underscore.downcase
end