Created
May 28, 2014 19:13
-
-
Save veloper/569e3d7d5dd2a9ab7fed to your computer and use it in GitHub Desktop.
Revisions
-
veloper created this gist
May 28, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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