Sha256: 05c0d23d3827fc30c6537213bc45bde07034a84801161d90db227b2159de5a04
Contents?: true
Size: 1.37 KB
Versions: 31
Compression:
Stored size: 1.37 KB
Contents
class Backend::TranslationWithSeoForm < Udongo::Form attr_reader :model, :translation, :seo delegate :id, to: :model attribute :seo_title, String attribute :seo_keywords, String attribute :seo_description, String attribute :seo_custom, String attribute :seo_slug, String validates :seo_slug, presence: true 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 def persisted? true end 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 def seo_attributes %w(title keywords description custom slug) end def non_seo_attributes attributes.keys.select { |k| !k.to_s.starts_with?('seo_') } end private def save_object non_seo_attributes.each do |f| @translation.send "#{f}=", self.send(f) end seo_attributes.each do |f| @seo.send("#{f}=", send("seo_#{f}")) end # Saves the model, translation and SEO info all at once. @seo.save! @model.save! end end
Version data entries
31 entries across 31 versions & 1 rubygems