From 3d0271669fe7d20d34bcb27110659e5ff91212a7 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 20 Jan 2015 17:57:38 +0200 Subject: [PATCH] Migration edit --- db/migrate/20150120140346_refactor_roles.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/db/migrate/20150120140346_refactor_roles.rb b/db/migrate/20150120140346_refactor_roles.rb index 192a6b710..c2e820288 100644 --- a/db/migrate/20150120140346_refactor_roles.rb +++ b/db/migrate/20150120140346_refactor_roles.rb @@ -1,13 +1,12 @@ class RefactorRoles < ActiveRecord::Migration - def change + def up add_column :users, :roles, :string, array: true User.all.each do |x| - c = x.role.try(:code) - if c - x.roles = [c] - x.save - end + r = x.role + next unless r + x.roles = [r.code] + x.save end remove_column :users, :role_id