Last active
July 11, 2016 00:08
-
-
Save acuppy/19599b06a2cbe50ed6b17b843c385bf4 to your computer and use it in GitHub Desktop.
This file contains 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 characters
namespace :data do | |
desc "Split the user's fullname into first and last names" | |
task :split_fullname => :environment do | |
User.reset_column_information | |
User.find_each do |user| | |
first_name, last_name = user.full_name.split '' | |
user.first_name = first_name | |
user.last_name = last_name | |
user.save! | |
end | |
end | |
end |
This file contains 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 characters
class AddFirstNameAndLastNameToUsers < ActiveRecord::Migration | |
def change | |
add_column :users, :first_name, :string | |
add_column :users, :last_name, :string | |
end | |
end |
This file contains 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 characters
class RemoveFullNameFromUsers < ActiveRecord::Migration | |
def change | |
remove_column :users, :full_name | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment