Sha256: ef283454322ca21eac4a45cf2f610d02f6093572596dc481601d2d1281146ea7

Contents?: true

Size: 964 Bytes

Versions: 88

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

class CreateStaticPages < ActiveRecord::Migration[5.1]
  class Organization < ApplicationRecord
    self.table_name = :decidim_organizations
  end

  class StaticPage < ApplicationRecord
    self.table_name = :decidim_static_pages
  end

  def change
    Organization.find_each do |organization|
      StaticPage.find_or_create_by!(slug: "initiatives") do |page|
        page.decidim_organization_id = organization.id
        page.title = localized_attribute(organization, "initiatives", :title)
        page.content = localized_attribute(organization, "initiatives", :content)
      end
    end
  end

  private

  def localized_attribute(organization, slug, attribute)
    organization.available_locales.inject({}) do |result, locale|
      text = I18n.with_locale(locale) do
        I18n.t(attribute, scope: "decidim.system.default_pages.placeholders", page: slug)
      end

      result.update(locale => text)
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
decidim-initiatives-0.29.1 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.4 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.27.9 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.29.0 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.3 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.27.8 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.29.0.rc4 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.29.0.rc3 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.29.0.rc2 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.29.0.rc1 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.2 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.27.7 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.1 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.27.6 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.26.10 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.26.9 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.0 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.27.5 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.0.rc5 db/migrate/20171023122747_create_static_pages.rb
decidim-initiatives-0.28.0.rc4 db/migrate/20171023122747_create_static_pages.rb