Module: Mongoid::DocumentEditor::DocumentsHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/mongoid/document_editor/documents_helper.rb
Instance Method Summary collapse
- #cell_value(document, header, config) ⇒ Object
- #document_edit_field(form, klass, document, name, config) ⇒ Object
- #model_param(model) ⇒ Object
- #relation_label(relation) ⇒ Object
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) = {} = {as: :boolean} if klass.fields[name].type == Boolean = {as: :numeric} if klass.fields[name].type == Integer = {as: :text} if type == :text = {collection: values} if values.present? .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, ) 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 |
#relation_label(relation) ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/helpers/mongoid/document_editor/documents_helper.rb', line 46 def relation_label(relation) if relation.respond_to?(:slug) return relation.slug else return relation.id end end |