From 43d87ecf98dd874f48b7ea29124f784386ec8255 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Mon, 2 May 2011 13:23:39 +0800 Subject: [PATCH] Destroy user_attributes and attribute_values when a user is destroyed --- app/controllers/panel/users_controller.rb | 4 ++++ app/models/user.rb | 1 + lib/tasks/dev.rake | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb index c0a2f526..7abf6e1f 100644 --- a/app/controllers/panel/users_controller.rb +++ b/app/controllers/panel/users_controller.rb @@ -65,6 +65,10 @@ class Panel::UsersController < ApplicationController else @user = User.find(params[:id]) @user.destroy + @user.user_attributes.each do |ua| + ua.attribute_values.each(&:destroy) + ua.destroy + end end redirect_to :action => :index diff --git a/app/models/user.rb b/app/models/user.rb index 5e047415..f7171723 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,6 +10,7 @@ class User field :admin, :type => Boolean, :default => true field :active_roles, :type => Array + has_many :user_attributes has_many :user_roles has_many :user_infos before_save :clean_active_roles diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 21b1880b..4d9651a1 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -41,8 +41,8 @@ namespace :dev do urm_2.attribute_models.build( :key => 'major', :locale => true, :i18n_variable_id => var_6.id, :markup => 'text_field', :list_options => [] ) urm_2.save! uim_1 = UserInfoModel.new( :key => 'profile', :i18n_variable_id => var_7.id, :built_in => true ) - uim_1.attribute_models.build( :key => 'family_name', :locale => true, :i18n_variable_id => var_8.id, :markup => 'text_field', :list_options => [] ) - uim_1.attribute_models.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [] ) + uim_1.attribute_models.build( :key => 'family_name', :locale => true, :i18n_variable_id => var_8.id, :markup => 'text_field', :list_options => [], :built_in => true ) + uim_1.attribute_models.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [], :built_in => true ) uim_1.save! layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read )