Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/lola/helpers.rb

Instance Method Summary collapse

Instance Method Details

#language_options_for_select(selected = nil, *priority_language_codes) ⇒ Object

Returns a string of option tags for pretty much any language in the world. Supply a language name as selected to have it marked as the selected option tag. You can also supply a list of language codes as additional parameters, so that they will be listed above the rest of the (long) list.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lola/helpers.rb', line 12

def language_options_for_select(selected = nil, *priority_language_codes)
  language_options = ""

  unless priority_language_codes.empty?
    priority_languages = Lola::languages.select do |pair| name, code = pair
      priority_language_codes.include?(code)
    end
    unless priority_languages.empty?
      language_options += options_for_select(priority_languages, selected)
      language_options += "\n<option value=\"\" disabled=\"disabled\">-------------</option>\n"
    end
  end

  language_options = language_options + options_for_select(Lola.languages, priority_language_codes.include?(selected) ? nil : selected)
  return language_options.html_safe
end

#language_select(object, method, priority_languages = nil, options = {}, html_options = {}) ⇒ Object

Return select and option tags for the given object and method, using language_options_for_select to generate the list of option tags.



5
6
7
# File 'lib/lola/helpers.rb', line 5

def language_select(object, method, priority_languages = nil, options = {}, html_options = {})
  InstanceTag.new(object, method, self, options.delete(:object)).to_language_select_tag(priority_languages, options, html_options)
end