Sha256: f7a297017aa7125adee6ac0dfff87029578a76452f35e27627dcb45e97da69b6

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

class UpdateUrlAndRedirectUrlValue < ActiveRecord::Migration
  def up
    @redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
    I18n.available_locales.each do |locale|
      move_url_to_redirect_url(locale.to_s.underscore)
    end
  end

  def down
    @redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
    I18n.available_locales.each do |locale|
      move_redirect_url_to_url(locale.to_s.underscore)
    end

  end

  def move_url_to_redirect_url(locale)
    I18n.with_locale(locale) do
      @redirect_pages.each do |redirect_page|
        redirect_url = redirect_page.url
        redirect_page.update_attributes(:url => update_url(redirect_page), :redirect_url => redirect_url) if redirect_page
      end
    end
  end

  def move_redirect_url_to_url(locale)
    I18n.with_locale(locale) do
      @redirect_pages.each do |redirect_page|
        url = redirect_page.redirect_url
        redirect_page.update_attributes(:url => url, :redirect_url => nil, :page_type => nil) if redirect_page
      end
    end
  end

  def update_url(page)
    complete_slug = ''
    if page.parent.present?
      complete_slug << page.parent.url.to_s
    else
      complete_slug = I18n.locale.to_s.underscore
    end
    complete_slug << "/#{page.slug}"
    complete_slug
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
kuhsaft-2.6.3 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.6.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.6.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.5.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.6.0 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.5.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.5.0 db/migrate/11_update_url_and_redirect_url_value.rb
qbrick-2.5.0.pre db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.4.3 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.4.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.4.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.4.0 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.6 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.5 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.4 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.3 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.2 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.1 db/migrate/11_update_url_and_redirect_url_value.rb
kuhsaft-2.3.0 db/migrate/11_update_url_and_redirect_url_value.rb