Class: Backend::TranslationWithSeoForm

Inherits:
Udongo::Form show all
Defined in:
app/forms/backend/translation_with_seo_form.rb

Direct Known Subclasses

ArticleTranslationForm, PageTranslationForm

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Udongo::Form

#init_attribute_values, #init_object_values, #save!

Constructor Details

#initialize(model, translation, seo) ⇒ TranslationWithSeoForm

Returns a new instance of TranslationWithSeoForm.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/forms/backend/translation_with_seo_form.rb', line 13

def initialize(model, translation, seo)
  @model = model
  @translation = translation
  @seo = seo

  non_seo_attributes.each do |f|
    self.send "#{f}=", @translation.send(f)
  end

  seo_attributes.each do |f|
    self.send("seo_#{f}=", @seo.send(f))
  end
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



2
3
4
# File 'app/forms/backend/translation_with_seo_form.rb', line 2

def model
  @model
end

#seoObject (readonly)

Returns the value of attribute seo.



2
3
4
# File 'app/forms/backend/translation_with_seo_form.rb', line 2

def seo
  @seo
end

#translationObject (readonly)

Returns the value of attribute translation.



2
3
4
# File 'app/forms/backend/translation_with_seo_form.rb', line 2

def translation
  @translation
end

Instance Method Details

#non_seo_attributesObject



52
53
54
# File 'app/forms/backend/translation_with_seo_form.rb', line 52

def non_seo_attributes
  attributes.keys.select { |k| !k.to_s.starts_with?('seo_') }
end

#persisted?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/forms/backend/translation_with_seo_form.rb', line 27

def persisted?
  true
end

#save(params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/forms/backend/translation_with_seo_form.rb', line 31

def save(params)
  non_seo_attributes.each do |f|
    self.send "#{f}=", params[f.to_sym]
  end

  seo_attributes.each do |f|
    self.send("seo_#{f}=", params["seo_#{f}".to_sym])
  end

  if valid?
    save_object
    true
  else
    false
  end
end

#seo_attributesObject



48
49
50
# File 'app/forms/backend/translation_with_seo_form.rb', line 48

def seo_attributes
  %w(title keywords description custom slug)
end