Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save veloper/569e3d7d5dd2a9ab7fed to your computer and use it in GitHub Desktop.
Save veloper/569e3d7d5dd2a9ab7fed to your computer and use it in GitHub Desktop.

Revisions

  1. veloper created this gist May 28, 2014.
    17 changes: 17 additions & 0 deletions 20140528183653_normalize_network_supplier_websites.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    class NormalizeNetworkSupplierWebsites < ActiveRecord::Migration

    class NetworkSuppliersTable < ActiveRecord::Base
    self.table_name = "network_suppliers"
    end

    def up
    NetworkSuppliersTable.where("website IS NOT NULL").find_each do |record|
    record.website = record.website.to_s.split.grep(UrlValidator::REGULAR_EXPRESSION).first # The first valid website or nil
    record.save! if record.changed?
    end
    end

    def down
    raise ActiveRecord::IrreversibleMigration
    end
    end