Class: SeoCpt::ManageByAdminOperation

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
app/concepts/seo_cpt/manage_by_admin_operation.rb

Instance Method Summary collapse

Instance Method Details

#update_attributes!(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/concepts/seo_cpt/manage_by_admin_operation.rb', line 7

def update_attributes!(options, *)
  model = options['model']
  Seo.translated_attribute_names.each do |attr|
    MyLocaleManager.available_locales.each do |locale|
      params = options['params']["#{attr}_#{locale}"].to_h.with_indifferent_access
      if params[:selected_mode] == 'manual'
        model.send("#{attr}_#{locale}=".to_sym, value_of(:manual, params))
        deactivate_related_settings(model, attr, locale)
        model.save!
      else
        settings = model.settings || {}
        settings["#{params[:selected_mode]}".to_sym] = true
        model.update! settings: settings
      end
    end
  end

  options['model'] = model

  true
end