Merge remote-tracking branch 'fsmanuel/master' into master.

Updated migration date to today.

Conflicts:
	db/schema.rb
This commit is contained in:
wvengen 2013-07-18 18:48:49 +02:00
commit 74bfc85562
21 changed files with 269 additions and 88 deletions

View file

@ -0,0 +1,34 @@
class MigrateUserSettings < ActiveRecord::Migration
def up
old_settings = ConfigurableSetting.all
old_settings.each do |old_setting|
# get target (user)
type = old_setting.configurable_type
id = old_setting.configurable_id
user = type.constantize.find(id)
# get the data (settings)
name = old_setting.name
namespace = name.split('.')[0]
key = name.split('.')[1].underscore # Camelcase to underscore
# prepare value
value = YAML.load(old_setting.value)
value = value.nil? ? false : value
# set the settings_attributes (thanks to settings.merge! we can set them one by one)
user.settings_attributes = {
"#{namespace}" => {
"#{key}" => value
}
}
# save the user to apply after_save callback
user.save
end
end
def down
end
end