Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_translation.rb

Instance Method Summary collapse

Instance Method Details

#globalize_fields_for(locale, *args, &proc) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/batch_translation.rb', line 6

def globalize_fields_for(locale, *args, &proc)
  raise ArgumentError, "Missing block" unless block_given?
  options = args.extract_options!
  @index = @index ? @index + 1 : 1
  object_name = "#{@object_name}[translations_attributes][#{@index}]"
  form_object = @object || @object_name.to_s.camelize.constantize.new
  object = form_object.translations.select{|t| t.locale.to_s == locale}.first || form_object.translations.find_by_locale(locale)
  @template.concat @template.hidden_field_tag("#{object_name}[id]", object ? object.id : "")
  @template.concat @template.hidden_field_tag("#{object_name}[locale]", locale)
  @template.fields_for(object_name, object, options, &proc)
end