Class: OptionsForSelectTag

Inherits:
LiquidumTag
  • Object
show all
Defined in:
lib/scribo/liquid/tags/options_for_select.rb

Overview

Add a text-field, either specifying everything manually or using a model object on the form

Basic usage:

{%assign airports = "Eindhoven, Schiphol" | split: ', '%}
{%options_for_select airports%}

Advanced usage:

{%assign airports = "Eindhoven, Schiphol" | split: ', '%}
{%options_for_select airports selected:"Schiphol" disabled:"Eindhoven"%}

Advanced usage:

{%options_for_select airports name value selected:"Schiphol" disabled:"Eindhoven"%}

This last usage requires a model on the form

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scribo/liquid/tags/options_for_select.rb', line 19

def render(context)
  super

  options = argv1.map(&:to_liquid)

  if sargs.present?
    options = options.map do |option|
      result = sargs.map { |a| option[a.to_s] }
      result = result.first if result.length == 1
      result
    end
  end

  context.registers['controller'].helpers.options_for_select(options, attr_args).to_s
end