Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Defined in:
- lib/helpers/helper.rb
Instance Method Summary collapse
- #globalize_fields_for_locale(locale, *args, &proc) ⇒ Object
- #globalize_fields_for_locales(locales = [], *args, &proc) ⇒ Object
-
#globalize_inputs(*args, &proc) ⇒ Object
Added “globalize_inputs” that uses standard Twitter Bootstrap tabs.
- #locale ⇒ Object
Instance Method Details
#globalize_fields_for_locale(locale, *args, &proc) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/helpers/helper.rb', line 8 def globalize_fields_for_locale(locale, *args, &proc) raise ArgumentError, "Missing block" unless block_given? @@active_locale = locale @index = @index ? @index + 1 : 1 object_name = "#{@object_name}[translations_attributes][#{@index}]" object = @object.translations.find_by_locale(locale.to_s) || @object.translations.new(:locale => locale) @template.concat(@template.hidden_field_tag("#{object_name}[id]", object.id)) unless object.new_record? @template.concat(@template.hidden_field_tag("#{object_name}[locale]", locale)) if @template.respond_to? :simple_fields_for @template.concat @template.simple_fields_for(object_name, object, *args, &proc) else @template.concat @template.fields_for(object_name, object, *args, &proc) end end |
#globalize_fields_for_locales(locales = [], *args, &proc) ⇒ Object
23 24 25 26 27 |
# File 'lib/helpers/helper.rb', line 23 def globalize_fields_for_locales(locales = [], *args, &proc) locales.each do |locale| globalize_fields_for_locale(locale, *args, &proc) end end |
#globalize_inputs(*args, &proc) ⇒ Object
Added “globalize_inputs” that uses standard Twitter Bootstrap tabs.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/helpers/helper.rb', line 30 def globalize_inputs(*args, &proc) index = [:child_index] || "#{self.object.class.to_s}-#{self.object.object_id}" linker = ActiveSupport::SafeBuffer.new fields = ActiveSupport::SafeBuffer.new ::I18n.available_locales.each do |locale| active_class = ::I18n.locale == locale ? "in active" : "" url = "lang-#{locale}-#{index}" linker << self.template.content_tag(:li, self.template.content_tag(:a, ::I18n.t("translation.#{locale}"), :href => "##{url}", :"data-toggle" => "tab" ), class: "#{active_class}", ) fields << self.template.content_tag(:div, self.semantic_fields_for(*(args.dup << self.object.translation_for(locale)), &proc), :id => "#{url}", class: "tab-pane fade #{active_class}" ) end linker = self.template.content_tag(:ul, linker, class: "nav nav-tabs language-selection") fields = self.template.content_tag(:div, fields, class: "tab-content") html = self.template.content_tag(:div, linker + fields, id: "language-tabs-#{index}", class: "tabbable tabs-left" ) end |
#locale ⇒ Object
4 5 6 |
# File 'lib/helpers/helper.rb', line 4 def locale @@active_locale end |