Skip to content

Instantly share code, notes, and snippets.

class AddPresentNameToComments < ActiveRecord::Migration[5.1]
def self.up
add_column :comments, :present_user_name, :string
Comment.includes(:user).all.find_each{|c| c.present_user_name = c.user.name}
end
def self.down
remove_column :comments, :present_user_name, :string
end
end