Destroy user_attributes and attribute_values when a user is destroyed

This commit is contained in:
chris2tof 2011-05-02 13:23:39 +08:00
parent 83bbd77d96
commit 43d87ecf98
3 changed files with 7 additions and 2 deletions

View File

@ -65,6 +65,10 @@ class Panel::UsersController < ApplicationController
else else
@user = User.find(params[:id]) @user = User.find(params[:id])
@user.destroy @user.destroy
@user.user_attributes.each do |ua|
ua.attribute_values.each(&:destroy)
ua.destroy
end
end end
redirect_to :action => :index redirect_to :action => :index

View File

@ -10,6 +10,7 @@ class User
field :admin, :type => Boolean, :default => true field :admin, :type => Boolean, :default => true
field :active_roles, :type => Array field :active_roles, :type => Array
has_many :user_attributes
has_many :user_roles has_many :user_roles
has_many :user_infos has_many :user_infos
before_save :clean_active_roles before_save :clean_active_roles

View File

@ -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.attribute_models.build( :key => 'major', :locale => true, :i18n_variable_id => var_6.id, :markup => 'text_field', :list_options => [] )
urm_2.save! urm_2.save!
uim_1 = UserInfoModel.new( :key => 'profile', :i18n_variable_id => var_7.id, :built_in => true ) 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 => '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 => [] ) 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! uim_1.save!
layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read ) layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read )