Class: DynamicScaffold::Form::Item::GlobalizeFields

Inherits:
Base
  • Object
show all
Defined in:
lib/dynamic_scaffold/form/item/globalize_fields.rb

Constant Summary

Constants inherited from Base

Base::ITEM_TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

create, #default, #default_value, #errors, #if, #insert, #label, #label?, #needs_rendering?, #note, #notes?, #proxy, #proxy_field, #render_label, #render_notes, #type?, #unless

Constructor Details

#initialize(config, type, locales, options = {}) ⇒ GlobalizeFields

Returns a new instance of GlobalizeFields.



8
9
10
11
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 8

def initialize(config, type, locales, options = {})
  super(config, type, :translations_attributes, options)
  @locales = locales
end

Instance Attribute Details

#localesObject (readonly)

Returns the value of attribute locales.



5
6
7
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 5

def locales
  @locales
end

Instance Method Details

#extract_parameters(permitting) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 21

def extract_parameters(permitting)
  trans = permitting.find {|item| item.is_a?(Hash) && item.key?(:translations_attributes) }
  if trans.nil?
    permitting << { translations_attributes: [:id, :locale, @item.name] }
  else
    trans[:translations_attributes] << @item.name
  end
end

#for(type, *args, &block) ⇒ Object



13
14
15
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 13

def for(type, *args, &block)
  @item = Form::Item::Base.create(@config, type, *args, &block)
end

#lang_attributes(classnames = nil) ⇒ Object



30
31
32
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 30

def lang_attributes(classnames = nil)
  build_html_attributes(classnames)
end

#locale_errors(locale, form) ⇒ Object



34
35
36
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 34

def locale_errors(locale, form)
  form.object.errors.full_messages_for("#{@item.proxy_field.name}_#{locale}")
end

#strong_parameterObject



17
18
19
# File 'lib/dynamic_scaffold/form/item/globalize_fields.rb', line 17

def strong_parameter
  { translations_attributes: [:id, :locale, @item.name] }
end