Class: LocalizedFields::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- LocalizedFields::FormBuilder
- Defined in:
- lib/localized_fields.rb
Instance Method Summary collapse
- #label(attribute, options = {}) ⇒ Object
- #language ⇒ Object
- #text_area(attribute, options = {}) ⇒ Object
- #text_field(attribute, options = {}) ⇒ Object
Instance Method Details
#label(attribute, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/localized_fields.rb', line 32 def label(attribute, = {}) if .has_key?(:language) language = [:language] super(attribute, for: "#{object_name}_#{attribute}_translations_#{language}").html_safe else field_name = @object_name.match(/.*\[(.*)_translations\]/)[1].capitalize super(attribute, field_name, ).html_safe end end |
#language ⇒ Object
28 29 30 |
# File 'lib/localized_fields.rb', line 28 def language [:language] if [:language] end |
#text_area(attribute, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/localized_fields.rb', line 58 def text_area(attribute, = {}) if .has_key?(:language) language = [:language] super(attribute, id: "#{object_name}_#{attribute}_translations_#{language}", name: "#{object_name}[#{attribute}_translations][#{language}]").html_safe else super(attribute, ).html_safe end end |
#text_field(attribute, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/localized_fields.rb', line 43 def text_field(attribute, = {}) if .has_key?(:language) language = [:language] translations = @object.send("#{attribute}_translations") || {} value = translations.has_key?(language.to_s) ? translations[language.to_s] : nil super(attribute, value: value, id: "#{object_name}_#{attribute}_translations_#{language}", name: "#{object_name}[#{attribute}_translations][#{language}]").html_safe else value = @object ? @object[attribute.to_s] : nil super(attribute, value: value).html_safe end end |