Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/localized_language_select.rb

Instance Method Summary collapse

Instance Method Details

#localized_language_options_for_select(selected = nil, priority_languages = nil, options = {}) ⇒ Object

Returns a string of option tags for languages according to locale. Supply the language code in lower-case (‘en’, ‘de’) as selected to have it marked as the selected option tag. Language codes listed as an array of symbols in priority_languages argument will be listed first



85
86
87
88
89
90
91
92
# File 'lib/localized_language_select.rb', line 85

def localized_language_options_for_select(selected = nil, priority_languages = nil, options = {})
  language_options = ""
  if priority_languages
    language_options += options_for_select(LocalizedLanguageSelect::priority_languages_array(priority_languages), selected)
    language_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
  end
  return language_options + options_for_select(LocalizedLanguageSelect::localized_languages_array(options), selected)
end

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

Return select and option tags for the given object and method, using localized_language_options_for_select to generate the list of option tags. Uses language code, not name as option value. Language codes listed as an array of symbols in priority_languages argument will be listed first TODO : Implement pseudo-named args with a hash, not the “somebody said PHP?” multiple args sillines



67
68
69
70
# File 'lib/localized_language_select.rb', line 67

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

#localized_language_select_tag(name, selected_value = nil, priority_languages = nil, html_options = {}) ⇒ Object

Return “named” select and option tags according to given arguments. Use selected_value for setting initial value It behaves likes older object-binded brother localized_language_select otherwise TODO : Implement pseudo-named args with a hash, not the “somebody said PHP?” multiple args sillines



76
77
78
79
80
# File 'lib/localized_language_select.rb', line 76

def localized_language_select_tag(name, selected_value = nil, priority_languages = nil, html_options = {})
   :select,
              localized_language_options_for_select(selected_value, priority_languages),
              { "name" => name, "id" => name }.update(html_options.stringify_keys)
end