OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / app / models / user.rb
1 class User < ActiveRecord::Base
2   has_one :author
3   
4   # Include default devise modules. Others available are:
5   # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
6   devise :database_authenticatable, :registerable,
7          :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
8
9   # Setup accessible (or protected) attributes for your model
10   attr_accessible :id, :name, :password, :password_confirmation, :remember_me , :email
11
12   def create_token
13     self.ensure_authentication_token
14     self.save
15   end
16   
17   def delete_token
18     self.authentication_token = nil
19     self.save
20   end
21   
22   def destroy
23     res = false
24     User.transaction do
25       self.author.comics.each do |comic|
26         raise ActiveRecord::Rollback unless comic.destroy_with_story
27       end
28       self.author.panels.each do |panel|
29         raise ActiveRecord::Rollback unless panel.destroy_with_elements
30       end
31       raise ActiveRecord::Rollback unless self.author.destroy
32       raise ActiveRecord::Rollback unless self.destroy
33       res = true
34     end
35     res
36   end
37   
38 end