Class: FieldsForTag

Inherits:
LiquidumBlock
  • Object
show all
Defined in:
lib/scribo/liquid/tags/fields_for_tag.rb

Overview

Exposes additional model objects, similar to form, but it doesn’t create a form-tag.

Basic usage:

{%fields_for location%}
  {%text_field city%}
{%endform%}

It will automatically build the association if need be. For polymorphic it needs a hint:

{%fields_for scribable Domain%}
  {%text_field city%}
{%endform%}

Available variables:

form.model

model specified

form.class_name

class name of the model specified (original name, not the drop)

form.errors

errors of the exposed object

require_relative ‘../drops/form_drop’

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scribo/liquid/tags/fields_for_tag.rb', line 24

def render(context)
  super

  result = ''

  context.stack do
    context['form'] = Scribo::FormDrop.new(new_model, argv1)
    result += render_body

    if context['form.model.id']
      result += %[<input] +
                attr_str(:id, arg(:id), input(:id, 'id')) +
                attr_str(:name, arg(:name), input(:name, 'id')) +
                attr_str(:value, arg(:value), input(:value, 'id')) +
                %[type="hidden"/>]
    end
  end

  result
end