Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/language-select.rb
Instance Method Summary collapse
-
#language_options_for_select(specific = nil, specific_languages = nil, additional_languages = nil, priority_languages = nil) ⇒ Object
Returns a string of option tags for standered languages in the world.
-
#language_select(object, method, specific_languages = nil, additional_languages = nil, 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.
Instance Method Details
#language_options_for_select(specific = nil, specific_languages = nil, additional_languages = nil, priority_languages = nil) ⇒ Object
Returns a string of option tags for standered languages in the world. You can also supply an array of languages as ‘specific_languages’, so that only they will be listed intead of the long list of languages. You can also supply an array of languages as ‘additional_languages’, so that they will be listed additinally to the default list.
You can also supply an array of languages as ‘priority_languages’, so that they will be listed above the rest of the (long) list.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/language-select.rb', line 23 def (specific = nil,specific_languages = nil, additional_languages = nil, priority_languages = nil) languages_list = FormOptionsHelper.language_list = "" # Adds the languages specified in the tag if specific_languages languages_list = Hash[ languages_list.select{|k, _| specific_languages.include?(k)} ] end # Adds additional languages if additional_languages languages_list = languages_list.merge(additional_languages).sort end # Adds the priority languages if priority_languages priority_languages_hash = Hash[ languages_list.select{|k, _| priority_languages.include?(k)} ] += (priority_languages_hash, specific) += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" specific=nil if priority_languages.include?(specific) end += (languages_list, specific) = .html_safe if .respond_to?(:html_safe) return end |
#language_select(object, method, specific_languages = nil, additional_languages = nil, 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.
14 15 16 |
# File 'lib/language-select.rb', line 14 def language_select(object, method, specific_languages = nil, additional_languages = nil, priority_languages = nil, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_language_select_tag(specific_languages, additional_languages, priority_languages, , ) end |